package com.movitech.mobile.cz.base.supplier.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movitech.mobile.cz.base.bizconfig.service.SSuppliersCategoryService;
import com.movitech.mobile.cz.base.common.aop.ServiceThrowable;
import com.movitech.mobile.cz.base.common.redis.RedisDBHelper;
import com.movitech.mobile.cz.base.common.util.*;
import com.movitech.mobile.cz.base.common.utils.IdGen;
import com.movitech.mobile.cz.base.modules.config.*;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.supplier.bizservice.SSuppliersSubmitOldSysInterfaceService;
import com.movitech.mobile.cz.base.supplier.bizvo.*;
import com.movitech.mobile.cz.base.supplier.entity.*;
import com.movitech.mobile.cz.base.supplier.entity.ext.*;
import com.movitech.mobile.cz.base.supplier.mapper.SSuppliersMapper;
import com.movitech.mobile.cz.base.supplier.mapper.ext.ExtSHistoryCommentMapper;
import com.movitech.mobile.cz.base.supplier.mapper.ext.ExtSSupplierFormModifyMappingMapper;
import com.movitech.mobile.cz.base.supplier.mapper.ext.ExtSSupplierRcRelateMapper;
import com.movitech.mobile.cz.base.supplier.mapper.ext.ExtSSuppliersMapper;
import com.movitech.mobile.cz.base.supplier.service.*;
import com.movitech.mobile.cz.base.syndata.SynDataService;
import com.movitech.mobile.cz.base.sys.bizvo.AttachmentVO;
import com.movitech.mobile.cz.base.sys.bizvo.UserRequestVO;
import com.movitech.mobile.cz.base.sys.entity.*;
import com.movitech.mobile.cz.base.sys.entity.ext.ExtSAttachment;
import com.movitech.mobile.cz.base.sys.entity.ext.ExtSMessages;
import com.movitech.mobile.cz.base.sys.mapper.SRegionalCompanyMapper;
import com.movitech.mobile.cz.base.sys.mapper.ext.ExtSMessagesMapper;
import com.movitech.mobile.cz.base.sys.service.*;
import com.movitech.mobile.cz.base.util.UserUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 供方基本情况 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-02-28
 */
@Service("sSuppliersService")
@Transactional
public class SSuppliersServiceImpl extends ServiceImpl<SSuppliersMapper, SSuppliers> implements SSuppliersService {

    private static Logger logger = org.apache.log4j.Logger.getLogger(SSuppliersServiceImpl.class);

    @Autowired
    private SSupplierQualificationGradeService sSupplierQualificationGradeService;
    @Autowired
    private SSupplierStockholderService sSupplierStockholderService;
    @Autowired
    private SSupplierContactInfoService sSupplierContactInfoService;
    @Autowired
    private SSupplierObtainInformationService sSupplierObtainInformationService;
    @Autowired
    private SSupplierRelateParentCmpyService sSupplierRelateParentCmpyService;
    @Autowired
    private SSupplierBankAccountService sSupplierBankAccountService;
    @Autowired
    private SSupplierBusinessSituationService sSupplierBusinessSituationService;

    @Autowired
    private SSuppliersLastThreeAchieveService sSuppliersLastThreeAchieveService;
    @Autowired
    private SSuppliersInspectionService sSuppliersInspectionService;
    @Autowired
    private SHistoryCommentService sHistoryCommentService;
    @Autowired
    private SAttachmentService sAttachmentService;
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SSupplierRcRelateService sSupplierRcRelateService;
    @Autowired
    private SSupplierCategoryRelateService sSupplierCategoryRelateService;
    @Autowired
    private ExtSSuppliersMapper extSSuppliersMapper;
    @Autowired
    private SysDictService sysDictService;
    @Autowired
    private SSuppliersCategoryService sSuppliersCategoryService;
    @Autowired
    private SRegionalCompanyService sRegionalCompanyService;
    @Autowired
    private SSupplierFormFieldsService sSupplierFormFieldsService;
    @Autowired
    private SSupplierFormModifyMappingService sSupplierFormModifyMappingService;
    @Autowired
    private SCommentConfigService sCommentConfigService;
    @Autowired
    private SMyDealsService sMyDealsService;
    @Autowired
    private ExtSSupplierFormModifyMappingMapper extSSupplierFormModifyMappingMapper;
    @Autowired
    private SSuppliersModifiedHistoryService sSuppliersModifiedHistoryService;
    @Autowired
    private SRegionalCompanyMapper sRegionalCompanyMapper;
    @Autowired
    private ExtSSupplierRcRelateMapper extSSupplierRcRelateMapper;
    @Autowired
    private ExtSMessagesMapper extSMessagesMapper;
    @Autowired
    private ExtSHistoryCommentMapper extSHistoryCommentMapper;
    @Autowired
    private SysAreaService sysAreaService;
    @Autowired
    RedisDBHelper<String, String> redisDBHelper;
    @Autowired
    private SynDataService synDataService;

    @Autowired
    private SSuppliersSubmitOldSysInterfaceService sSuppliersSubmitOldSysInterfaceService;

    @Override
    public List<ExtSSuppliers> getSuppliersByIdOrCode(Map<String, Object> mapParms) {
        return extSSuppliersMapper.getSuppliersByIdOrCode(mapParms);
    }

    /***
     * 根据id，获取详情SuppliersDetailVO对象
     * @param id
     * @return
     */
    public RestReturnResult<SuppliersDetailVO> getSuppliersById(String id) {
        RestReturnResult<SuppliersDetailVO> hResult = new RestReturnResult<SuppliersDetailVO>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
        if (StringUtils.isEmpty(id)) {
            hResult = new RestReturnResult<SuppliersDetailVO>(CommonConstants.FAIL, "id为空");
            return hResult;
        }
        SuppliersDetailVO suppliersVO = new SuppliersDetailVO();
        try {
            //基本信息 主表信息
            ExtSSuppliers sSuppliers = extSSuppliersMapper.getExtById(id);
            SuppliersVO suppliersVOInfo = new SuppliersVO();
            if (sSuppliers == null) {
                throw new RuntimeException("数据不存在!", new ServiceThrowable());
            }
            BeanUtils.copyProperties(sSuppliers, suppliersVOInfo);
            SysUser user = sysUserService.selectById(sSuppliers.getSysUserId());
            if (user != null) {
                suppliersVOInfo.setUserName(user.getLoginName());
                if (user.getLoginFlag() != null) suppliersVOInfo.setLoginFlag(Integer.valueOf(user.getLoginFlag()));
            }
            suppliersVOInfo.setRegisterStatusName(RegisterStatusEnum.getDesc(sSuppliers.getRegisterStatus() + ""));
            suppliersVOInfo.setSupplierStatusName(SupplierStatusEnum.getDesc(sSuppliers.getSupplierStatus() + ""));
            suppliersVOInfo.setTaxipayerStatusName(EnumConstant.taxipayerStatus.getDesc(sSuppliers.getTaxipayerStatus() + ""));
            suppliersVOInfo.setEnterpriseCharacterizeName(EnumConstant.recommenderType.getDesc(sSuppliers.getEnterpriseCharacterize() + ""));
            suppliersVOInfo.setSupplierBigStatusName(SupplierBigStatusEnum.getDesc(sSuppliers.getSupplierBigStatus()));

            //服务分类
            String supplierServiceCategoryIds = sSuppliers.getSupplierServiceCategoryIds();
            if (StringUtils.isNotEmpty(supplierServiceCategoryIds)) {
                String[] supplierServiceCategoryIdArr = supplierServiceCategoryIds.split(",");
                String supplierServiceCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierServiceCategoryIdArr);
                suppliersVOInfo.setSupplierServiceCategoryNames(supplierServiceCategoryNames);
            }

            //承接省份
            String undertakeAreas = sSuppliers.getUndertakeAreas();
            if (StringUtils.isNotEmpty(undertakeAreas)) {
                String[] idArr = undertakeAreas.split(",");
                String names = sysAreaService.getAreaNames(idArr);
                suppliersVOInfo.setUndertakeAreasNames(names);
            }

            //供方分类
            String supplierCategoryIds = sSuppliers.getSupplierCategoryIds();
            if (StringUtils.isNotEmpty(supplierCategoryIds)) {
                String[] supplierCategoryIdArr = supplierCategoryIds.split(",");
                String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                suppliersVOInfo.setSupplierCategoryNames(supplierCategoryNames);
            }

            //意向地区公司
            String intentionRegionalCompanyIds = sSuppliers.getIntentionRegionalCompanyIds();
            if (StringUtils.isNotEmpty(intentionRegionalCompanyIds)) {
                String[] intentionRegionalCompanyIdArr = intentionRegionalCompanyIds.split(",");
                String intentionRegionalCompanyNames = sRegionalCompanyService.getRegionalCompanyNames(intentionRegionalCompanyIdArr);
                suppliersVOInfo.setIntentionRegionalCompanyNames(intentionRegionalCompanyNames);
            }

            //服务地区公司
//            String serviceRegionalCompanyIds = sSuppliers.getServiceRegionalCompanyIds();
            String serviceRegionalCompanyIds = extSSupplierRcRelateMapper.getQualifiedCompIds(SupplierBigStatusEnum.QUALIFIED.getCode() + "", id);
            if (StringUtils.isNotEmpty(serviceRegionalCompanyIds)) {
                String[] serviceRegionalCompanyIdArr = serviceRegionalCompanyIds.split(",");
                String serviceRegionalCompanyNames = sRegionalCompanyService.getRegionalCompanyNames(serviceRegionalCompanyIdArr);
                suppliersVOInfo.setServiceRegionalCompanyNames(serviceRegionalCompanyNames);
                suppliersVOInfo.setServiceRegionalCompanyIds(serviceRegionalCompanyIds);
            }

            //合格分类
//            String qualifiedCategoryIds=extSSupplierRcRelateMapper.getQualifiedCategoryIds(SupplierBigStatusEnum.QUALIFIED.getCode()+"",id);
            if (StringUtils.isNotEmpty(sSuppliers.getQualifiedCategoryIds())) {
                String[] supplierCategoryIdArr = sSuppliers.getQualifiedCategoryIds().split(",");
                List<String> tempList = new ArrayList<String>();
                String ids = "";
                for (int i = 0; i < supplierCategoryIdArr.length; i++) {
                    if (!tempList.contains(supplierCategoryIdArr[i])) {
                        tempList.add(supplierCategoryIdArr[i]);
                        ids = ids + supplierCategoryIdArr[i] + ",";
                    }
                }
                if (tempList != null && tempList.size() > 0) {
                    supplierCategoryIdArr = (String[]) tempList.toArray(new String[tempList.size()]);
                    String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                    suppliersVOInfo.setQualifiedCategoryNames(supplierCategoryNames);
                    if (ids.endsWith(",")) {
                        ids = ids.substring(0, ids.length() - 1);
                    }
                    suppliersVOInfo.setQualifiedCategoryIds(ids);
                }
            }
            suppliersVO.setSuppliersVO(suppliersVOInfo);

            suppliersVO.setEditFlage(CommonConstants.YES_INTEGER);
            //是否可以修改
            if (sSuppliers.getModifiedFlag() != null && sSuppliers.getModifiedFlag() == CommonConstants.YES_INTEGER) {
                suppliersVO.setEditFlage(CommonConstants.NO_INTEGER);
            } else {
                //查询入库审批中意向地区公司数量
                EntityWrapper rcRelateWrapper = new EntityWrapper();
                SSupplierRcRelate rcRelateObj = new SSupplierRcRelate();
                rcRelateObj.setSuppliersId(sSuppliers.getId());
                rcRelateObj.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
                rcRelateObj.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.STORE_APPROVE_ING.getCode()));
                rcRelateWrapper.setEntity(rcRelateObj);
                int countStoring = sSupplierRcRelateService.selectCount(rcRelateWrapper);
                if (countStoring > 0) {
                    suppliersVO.setEditFlage(CommonConstants.NO_INTEGER);
                }
            }

            //是否合格
//            List<ExtSSuppliers> qualifiedSupplierLs=extSSuppliersMapper.getCompanyListByStatus(SupplierStatusEnum.QUALIFIED.getCode()+"",id);
            List<ExtSSupplierRcRelate> qualifiedSupplierLs = extSSupplierRcRelateMapper.getCompanyListByStatus(SupplierBigStatusEnum.QUALIFIED.getCode() + "", id);
            if (qualifiedSupplierLs != null && qualifiedSupplierLs.size() > 0) {
                suppliersVO.setQualifiedFlag(CommonConstants.YES_INTEGER);
            } else {
                suppliersVO.setQualifiedFlag(CommonConstants.NO_INTEGER);
            }

            EntityWrapper wrapper = new EntityWrapper<>();
            wrapper.orderBy(" create_date ", false);
            //根据suppliers_id查询供方信息-资质等级
            SSupplierQualificationGrade sSupplierQualificationGrade = new SSupplierQualificationGrade();
            sSupplierQualificationGrade.setSuppliersId(id);
            sSupplierQualificationGrade.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierQualificationGrade);
            List<SSupplierQualificationGrade> sSupplierQualificationGradels = sSupplierQualificationGradeService.selectList(wrapper);
            List<SuppliersQualificationGradeVO> suppliersQualificationGradeVOls = ListObjCopyUtil.copyTo(sSupplierQualificationGradels, SuppliersQualificationGradeVO.class);
//			List<SuppliersQualificationGradeVO> suppliersQualificationGradeVOls=sSupplierQualificationGradeService.selectObjs(wrapper);
            suppliersVO.setLstSuppliersQualificationGradeVO(suppliersQualificationGradeVOls);

            //根据suppliers_id查询供方信息-股东
            SSupplierStockholder sSupplierStockholder = new SSupplierStockholder();
            sSupplierStockholder.setSuppliersId(id);
            sSupplierStockholder.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierStockholder);
            List<SSupplierStockholder> sSupplierStockholderls = sSupplierStockholderService.selectList(wrapper);
            List<SuppliersStockHolderVO> suppliersStockHolderVOls = ListObjCopyUtil.copyTo(sSupplierStockholderls, SuppliersStockHolderVO.class);
//			List<SuppliersStockHolderVO> SuppliersStockHolderVOls=sSupplierStockholderService.selectObjs(wrapper);
            //前端需求---当没有股东时添加一个空的股东对象
            if (suppliersStockHolderVOls == null || suppliersStockHolderVOls.size() == 0) {
                SuppliersStockHolderVO suppliersStockHolderVO = new SuppliersStockHolderVO();
                suppliersStockHolderVOls = new ArrayList<>();
                suppliersStockHolderVOls.add(suppliersStockHolderVO);
            }
            suppliersVO.setLstSuppliersStockHolderVO(suppliersStockHolderVOls);

            //根据suppliers_id查询供方信息-联系方式
            SSupplierContactInfo sSupplierContactInfo = new SSupplierContactInfo();
            sSupplierContactInfo.setSuppliersId(id);
            sSupplierContactInfo.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierContactInfo);
            List<SSupplierContactInfo> sSupplierContactInfols = sSupplierContactInfoService.selectList(wrapper);
            List<SuppliersContactInfoVO> suppliersContactInfoVOls = ListObjCopyUtil.copyTo(sSupplierContactInfols, SuppliersContactInfoVO.class);
//			List<SuppliersContactInfoVO> suppliersContactInfoVOls=sSupplierContactInfoService.selectObjs(wrapper);
            //前端需求--当没有主联系人时返回值添加一个空的主联系人
            boolean existMain = false;
            ArrayList suppliersContactInfoVOlsCopy = new ArrayList<>(suppliersContactInfoVOls);
            for (int i = suppliersContactInfoVOls.size() - 1; i >= 0; i--) {
                SuppliersContactInfoVO suppliersContactInfoVO = suppliersContactInfoVOls.get(i);
                if (suppliersContactInfoVO.getMainFlag() != null && 1 == suppliersContactInfoVO.getMainFlag()) {
                    existMain = true;
                    suppliersContactInfoVOlsCopy.remove(suppliersContactInfoVO);
                    suppliersContactInfoVOlsCopy.add(0, suppliersContactInfoVO);
                }
            }
            if (!existMain) {
                if (suppliersContactInfoVOlsCopy == null) {
                    suppliersContactInfoVOlsCopy = new ArrayList();
                }
                SuppliersContactInfoVO suppliersContactInfoVO = new SuppliersContactInfoVO();
                suppliersContactInfoVO.setMainFlag(CommonConstants.MAIN_CONTACTS);//是否主联系人（0：否，1：是）
                suppliersContactInfoVOlsCopy.add(0, suppliersContactInfoVO);
            }
            suppliersVO.setLstSuppliersContactInfoVO(suppliersContactInfoVOlsCopy);

            //根据suppliers_id查询供方信息-获取信息类型
            SSupplierObtainInformation sSupplierObtainInformation = new SSupplierObtainInformation();
            sSupplierObtainInformation.setSuppliersId(id);
            sSupplierObtainInformation.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierObtainInformation);
            SuppliersObtainInformationVO suppliersObtainInformationVO = new SuppliersObtainInformationVO();
            sSupplierObtainInformation = sSupplierObtainInformationService.selectOne(wrapper);
            if (sSupplierObtainInformation != null)
                BeanUtils.copyProperties(sSupplierObtainInformation, suppliersObtainInformationVO);
            suppliersObtainInformationVO.setRecommenderTypeName(EnumConstant.recommenderType.getDesc(suppliersObtainInformationVO.getRecommenderType() + ""));
            suppliersVO.setSuppliersObtainInformationVO(suppliersObtainInformationVO);

            //根据suppliers_id查询供方信息-关联母公司信息
            SSupplierRelateParentCmpy sSupplierRelateParentCmpy = new SSupplierRelateParentCmpy();
            sSupplierRelateParentCmpy.setSuppliersId(id);
            sSupplierRelateParentCmpy.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierRelateParentCmpy);
            SuppliersRelateParentCmpyVO suppliersRelateParentCmpyVO = new SuppliersRelateParentCmpyVO();
            sSupplierRelateParentCmpy = sSupplierRelateParentCmpyService.selectOne(wrapper);
            if (sSupplierRelateParentCmpy != null)
                BeanUtils.copyProperties(sSupplierRelateParentCmpy, suppliersRelateParentCmpyVO);
            suppliersVO.setSuppliersRelateParentCmpyVO(suppliersRelateParentCmpyVO);

            //根据suppliers_id查询供方信息-业务状况
            SSupplierBusinessSituation sSupplierBusinessSituation = new SSupplierBusinessSituation();
            sSupplierBusinessSituation.setSuppliersId(id);
            sSupplierBusinessSituation.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierBusinessSituation);
            SuppliersBusinessSituationVO suppliersBusinessSituationVO = new SuppliersBusinessSituationVO();
            sSupplierBusinessSituation = sSupplierBusinessSituationService.selectOne(wrapper);
            if (sSupplierBusinessSituation != null)
                BeanUtils.copyProperties(sSupplierBusinessSituation, suppliersBusinessSituationVO);
            suppliersVO.setSuppliersBusinessSituationVO(suppliersBusinessSituationVO);

            //根据suppliers_id查询供方信息-近三年业绩 战略合作
            SSuppliersLastThreeAchieve sSuppliersLastThreeAchieveMajor = new SSuppliersLastThreeAchieve();
            sSuppliersLastThreeAchieveMajor.setSuppliersId(id);
            sSuppliersLastThreeAchieveMajor.setCooperativeType(CommonConstants.MAJOR_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
            sSuppliersLastThreeAchieveMajor.setSourceType(CommonConstants.EXTERNAL);//来源（0：外部，1：内部）
            sSuppliersLastThreeAchieveMajor.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSuppliersLastThreeAchieveMajor);
            List<SSuppliersLastThreeAchieve> sSuppliersLastThreeAchievelsMajor = sSuppliersLastThreeAchieveService.selectList(wrapper);
            List<SuppliersLastThreeMajorAchievenVO> suppliersLastThreeAchievenVOlsMajor = ListObjCopyUtil.copyTo(sSuppliersLastThreeAchievelsMajor, SuppliersLastThreeMajorAchievenVO.class);
            for (SuppliersLastThreeMajorAchievenVO suppliersLastThreeMajorAchievenVO : suppliersLastThreeAchievenVOlsMajor) {
                //根据suppliers_id、RelatedId查询供方信息-附件清单
                SAttachment sAttachment = new SAttachment();
                sAttachment.setFormId(id);
                sAttachment.setRelatedId(suppliersLastThreeMajorAchievenVO.getId());
                sAttachment.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
                wrapper.setEntity(sAttachment);
                List<SAttachment> sAttachmentls = sAttachmentService.selectList(wrapper);
                List<AttachmentVO> attachmentVOls = ListObjCopyUtil.copyTo(sAttachmentls, AttachmentVO.class);
                suppliersLastThreeMajorAchievenVO.setLstattachmentVO(attachmentVOls);
            }
            //前端需求
            if (suppliersLastThreeAchievenVOlsMajor == null || suppliersLastThreeAchievenVOlsMajor.size() == 0) {
                SuppliersLastThreeMajorAchievenVO suppliersLastThreeMajorAchievenVO = new SuppliersLastThreeMajorAchievenVO();
                suppliersLastThreeMajorAchievenVO.setLstattachmentVO(new ArrayList<>());
                suppliersLastThreeAchievenVOlsMajor = new ArrayList<>();
                suppliersLastThreeAchievenVOlsMajor.add(suppliersLastThreeMajorAchievenVO);
            }
            suppliersVO.setLstSuppliersLastThreeMajorAchievenVO(suppliersLastThreeAchievenVOlsMajor);

            //根据suppliers_id查询供方信息-近三年业绩 一般合作
            SSuppliersLastThreeAchieve sSuppliersLastThreeAchieveCommon = new SSuppliersLastThreeAchieve();
            sSuppliersLastThreeAchieveCommon.setSuppliersId(id);
            sSuppliersLastThreeAchieveCommon.setCooperativeType(CommonConstants.COMMON_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
            sSuppliersLastThreeAchieveCommon.setSourceType(CommonConstants.EXTERNAL);//来源（0：外部，1：内部）
            sSuppliersLastThreeAchieveCommon.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSuppliersLastThreeAchieveCommon);
            List<SSuppliersLastThreeAchieve> sSuppliersLastThreeAchievelsCommon = sSuppliersLastThreeAchieveService.selectList(wrapper);
            List<SuppliersLastThreeCommonAchievenVO> suppliersLastThreeAchievenVOlsCommon = ListObjCopyUtil.copyTo(sSuppliersLastThreeAchievelsCommon, SuppliersLastThreeCommonAchievenVO.class);
            for (SuppliersLastThreeCommonAchievenVO suppliersLastThreeCommonAchievenVO : suppliersLastThreeAchievenVOlsCommon) {
                //根据suppliers_id、RelatedId查询供方信息-附件清单
                SAttachment sAttachment = new SAttachment();
                sAttachment.setFormId(id);
                sAttachment.setRelatedId(suppliersLastThreeCommonAchievenVO.getId());
                sAttachment.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
                wrapper.setEntity(sAttachment);
                List<SAttachment> sAttachmentls = sAttachmentService.selectList(wrapper);
                List<AttachmentVO> attachmentVOls = ListObjCopyUtil.copyTo(sAttachmentls, AttachmentVO.class);
                suppliersLastThreeCommonAchievenVO.setLstattachmentVO(attachmentVOls);
            }
            //前端需求
            if (suppliersLastThreeAchievenVOlsCommon == null || suppliersLastThreeAchievenVOlsCommon.size() == 0) {
                SuppliersLastThreeCommonAchievenVO suppliersLastThreeCommonAchievenVO = new SuppliersLastThreeCommonAchievenVO();
                suppliersLastThreeCommonAchievenVO.setLstattachmentVO(new ArrayList<>());
                suppliersLastThreeAchievenVOlsCommon = new ArrayList<>();
                suppliersLastThreeAchievenVOlsCommon.add(suppliersLastThreeCommonAchievenVO);
            }
            suppliersVO.setLstSuppliersLastThreeCommonAchievenVO(suppliersLastThreeAchievenVOlsCommon);

            //根据suppliers_id查询供方信息内部业绩
            SSuppliersLastThreeAchieve sSuppliersLastThreeAchieve = new SSuppliersLastThreeAchieve();
            sSuppliersLastThreeAchieve.setSuppliersId(id);
            sSuppliersLastThreeAchieve.setSourceType(CommonConstants.INNER);//来源（0：外部，1：内部）
            sSuppliersLastThreeAchieve.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSuppliersLastThreeAchieve);
            List<SSuppliersLastThreeAchieve> sSuppliersLastThreeAchievels = sSuppliersLastThreeAchieveService.selectList(wrapper);
            List<SuppliersLastThreeAchievenVO> suppliersLastThreeAchievenVOls = ListObjCopyUtil.copyTo(sSuppliersLastThreeAchievels, SuppliersLastThreeAchievenVO.class);
            for (SuppliersLastThreeAchievenVO suppliersLastThreeAchievenVO : suppliersLastThreeAchievenVOls) {
                suppliersLastThreeAchievenVO.setContactStatusName(ContactStatusEnum.getDesc(suppliersLastThreeAchievenVO.getContactStatus()));
            }
//            List<SuppliersLastThreeAchievenVO> suppliersLastThreeAchievenVOlsCopy=new ArrayList<>();
//            for (SuppliersLastThreeAchievenVO suppliersLastThreeAchievenVO : suppliersLastThreeAchievenVOls) {
//                //根据suppliers_id、RelatedId查询供方信息-附件清单
//                SAttachment sAttachment = new SAttachment();
//                sAttachment.setFormId(id);
//                sAttachment.setRelatedId(suppliersLastThreeAchievenVO.getId());
//                wrapper.setEntity(sAttachment);
//                List<SAttachment> sAttachmentls = sAttachmentService.selectList(wrapper);
//                List<AttachmentVO> attachmentVOls = ListObjCopyUtil.copyTo(sAttachmentls, AttachmentVO.class);
//                suppliersLastThreeAchievenVO.setLstattachmentVO(attachmentVOls);
//                if(suppliersLastThreeAchievenVO.getCooperativeType()==CommonConstants.MAJOR_COOPRATIVE){
//                    suppliersLastThreeAchievenVOlsCopy.add(0,suppliersLastThreeAchievenVO);
//                }else{
//                    suppliersLastThreeAchievenVOlsCopy.add(suppliersLastThreeAchievenVO);
//                }
//            }
            suppliersVO.setLstSuppliersInnerLastThreeAchievenVO(suppliersLastThreeAchievenVOls);

            //根据suppliers_id查询供方信息-附件清单
            SAttachment sAttachment = new SAttachment();
            sAttachment.setFormId(id);
            sAttachment.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sAttachment);
            List<SAttachment> sAttachmentls = sAttachmentService.selectList(wrapper);
            List<AttachmentVO> attachmentVOls = ListObjCopyUtil.copyTo(sAttachmentls, AttachmentVO.class);
            Map<Integer, List<AttachmentVO>> mapAttachmentVO = new HashMap<>();
            for (AttachmentVO attachmentVO : attachmentVOls) {
                if (AttachmentTypeEnum.ATTACHMENT_TYPE_1.getCode() == attachmentVO.getAttachmentType() ||//过滤附件类型1：供方三年业绩合同附件
                        AttachmentTypeEnum.ATTACHMENT_TYPE_13.getCode() == attachmentVO.getAttachmentType())
                    continue;//过滤附件类型13：供方考察报告附件
                List<AttachmentVO> ls = mapAttachmentVO.get(Integer.valueOf(attachmentVO.getAttachmentType()));
                if (ls == null) ls = new ArrayList<AttachmentVO>();
                ls.add(attachmentVO);
                mapAttachmentVO.put(Integer.valueOf(attachmentVO.getAttachmentType()), ls);
            }
            suppliersVO.setMapAttachmentVOs(mapAttachmentVO);

            //根据suppliers_id查询供方信息-考察报告
            List<ExtSSuppliersInspection> sSuppliersInspectionExtls = sSuppliersInspectionService.getListBySupplierId(id);
            List<SuppliersInspectionVO> sSuppliersInspectionls = ListObjCopyUtil.copyTo(sSuppliersInspectionExtls, SuppliersInspectionVO.class);
            for (SuppliersInspectionVO suppliersInspectionVO : sSuppliersInspectionls) {
                if (StringUtils.isNotEmpty(suppliersInspectionVO.getInspectionMemberUserIds())) {
                    String names = sysUserService.getSysUserNameByIds(suppliersInspectionVO.getInspectionMemberUserIds());
                    if (StringUtils.isNotEmpty(names)) {
                        suppliersInspectionVO.setInspectionMemberUserNames(names);
                    }
                }
                //供方分类
                String rcsupplierCategoryIds = suppliersInspectionVO.getSupplierCategoryIds();
                if (StringUtils.isNotEmpty(rcsupplierCategoryIds)) {
                    String[] supplierCategoryIdArr = rcsupplierCategoryIds.split(",");
                    String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                    suppliersInspectionVO.setSupplierCategoryNames(supplierCategoryNames);
                }
                //供方分类
                String supplierCategoryActualIds = suppliersInspectionVO.getSupplierCategoryActualIds();
                if (StringUtils.isNotEmpty(supplierCategoryActualIds)) {
                    String[] supplierCategoryIdArr = supplierCategoryActualIds.split(",");
                    String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                    suppliersInspectionVO.setSupplierCategoryActualNames(supplierCategoryNames);
                }
                //根据suppliers_id、RelatedId查询供方信息-附件清单
                SAttachment obj = new SAttachment();
                obj.setFormId(id);
                obj.setRelatedId(suppliersInspectionVO.getId());
                obj.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
                wrapper.setEntity(obj);
                List<SAttachment> attachmentList = sAttachmentService.selectList(wrapper);
                List<AttachmentVO> attachmentVOList = ListObjCopyUtil.copyTo(attachmentList, AttachmentVO.class);
                suppliersInspectionVO.setLstAttachmentVO(attachmentVOList);
            }
//			List<SuppliersInspectionVO> suppliersInspectionVOls=sSuppliersInspectionService.selectObjs(wrapper);
            suppliersVO.setLstSuppliersInspectionVO(sSuppliersInspectionls);

            //根据suppliers_id查询供方信息-审批历程
            List<ExtSHistoryComment> sHistoryCommentls = extSHistoryCommentMapper.getCommentList(id, HistoryCommentTypeEnum.INTERNET.getCode());
            List<HistoryCommentVO> historyCommentVOls = ListObjCopyUtil.copyTo(sHistoryCommentls, HistoryCommentVO.class);
//			List<HistoryCommentVO> historyCommentVOls=sHistoryCommentService.selectObjs(wrapper);
            suppliersVO.setLstHistoryCommentVO(historyCommentVOls);

            //根据suppliers_id查询供方信息-外网审核记录
            List<ExtSHistoryComment> sHistoryCommentExtLs = extSHistoryCommentMapper.getCommentList(id, HistoryCommentTypeEnum.INTRANET.getCode());
            List<HistoryCommentVO> historyCommentVOExtls = ListObjCopyUtil.copyTo(sHistoryCommentExtLs, HistoryCommentVO.class);
            suppliersVO.setLstHistoryCommentOutVO(historyCommentVOExtls);

            //变更历史
            List<ExtSSuppliersModifiedHistory> ls = sSuppliersModifiedHistoryService.getListBySupplerId(id);
            List<SuppliersModifiedHistoryVO> lsVo = ListObjCopyUtil.copyTo(ls, SuppliersModifiedHistoryVO.class);
            suppliersVO.setSuppliersModifiedHistoryVO(lsVo);


            //根据suppliers_id查询供方信息-银行账号
            SSupplierBankAccount sSupplierBankAccount = new SSupplierBankAccount();
            sSupplierBankAccount.setSuppliersId(id);
            sSupplierBankAccount.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierBankAccount);
            List<SSupplierBankAccount> lstSupplierBankAccount = sSupplierBankAccountService.selectList(wrapper);
            if (lstSupplierBankAccount != null) {
                suppliersVO.setLstSuppliersBankAccountVO(ListObjCopyUtil.copyTo(lstSupplierBankAccount, SuppliersBankAccountVO.class));
            }

            hResult = new RestReturnResult<SuppliersDetailVO>(CommonConstants.SUCCESS, suppliersVO);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
        return hResult;
    }

    /***
     * 根据子表id，获取详情SuppliersDetailVO对象
     * @param relatedId
     * @return
     */
    public RestReturnResult<SuppliersDetailVO> getByRelatedId(String relatedId) {
        RestReturnResult<SuppliersDetailVO> hResult = new RestReturnResult<SuppliersDetailVO>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
        if (StringUtils.isEmpty(relatedId)) {
            hResult = new RestReturnResult<SuppliersDetailVO>(CommonConstants.FAIL, "id为空");
            return hResult;
        }
        SuppliersDetailVO suppliersVO = new SuppliersDetailVO();
        try {
            //基本信息 主表信息
            ExtSSuppliers sSuppliers = extSSuppliersMapper.getByRelatedId(relatedId);
            SuppliersVO suppliersVOInfo = new SuppliersVO();
            if (sSuppliers == null) {
                throw new RuntimeException("数据不存在!", new ServiceThrowable());
            }
            String id = sSuppliers.getId();
            BeanUtils.copyProperties(sSuppliers, suppliersVOInfo);
            SysUser user = sysUserService.selectById(sSuppliers.getSysUserId());
            if (user != null) {
                suppliersVOInfo.setUserName(user.getLoginName());
                if (user.getLoginFlag() != null) suppliersVOInfo.setLoginFlag(Integer.valueOf(user.getLoginFlag()));
            }
            suppliersVOInfo.setRegisterStatusName(RegisterStatusEnum.getDesc(sSuppliers.getRegisterStatus() + ""));
            suppliersVOInfo.setSupplierStatusName(SupplierStatusEnum.getDesc(sSuppliers.getSupplierStatus() + ""));
            suppliersVOInfo.setTaxipayerStatusName(EnumConstant.taxipayerStatus.getDesc(sSuppliers.getTaxipayerStatus() + ""));
            suppliersVOInfo.setEnterpriseCharacterizeName(EnumConstant.recommenderType.getDesc(sSuppliers.getEnterpriseCharacterize() + ""));
            suppliersVOInfo.setSupplierBigStatusName(SupplierBigStatusEnum.getDesc(sSuppliers.getSupplierBigStatus()));

            //服务分类
            String supplierServiceCategoryIds = sSuppliers.getSupplierServiceCategoryIds();
            if (StringUtils.isNotEmpty(supplierServiceCategoryIds)) {
                String[] supplierServiceCategoryIdArr = supplierServiceCategoryIds.split(",");
                String supplierServiceCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierServiceCategoryIdArr);
                suppliersVOInfo.setSupplierServiceCategoryNames(supplierServiceCategoryNames);
            }

            //承接省份
            String undertakeAreas = sSuppliers.getUndertakeAreas();
            if (StringUtils.isNotEmpty(undertakeAreas)) {
                String[] idArr = undertakeAreas.split(",");
                String names = sysAreaService.getAreaNames(idArr);
                suppliersVOInfo.setUndertakeAreasNames(names);
            }

            //供方分类
            String supplierCategoryIds = sSuppliers.getSupplierCategoryIds();
            if (StringUtils.isNotEmpty(supplierCategoryIds)) {
                String[] supplierCategoryIdArr = supplierCategoryIds.split(",");
                String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                suppliersVOInfo.setSupplierCategoryNames(supplierCategoryNames);
            }

            //合格分类
            String qualifiedCategoryIds = sSuppliers.getQualifiedCategoryIds();
            if (StringUtils.isNotEmpty(qualifiedCategoryIds)) {
                String[] supplierCategoryIdArr = qualifiedCategoryIds.split(",");
                String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                suppliersVOInfo.setQualifiedCategoryNames(supplierCategoryNames);
            }

            //意向地区公司
            String intentionRegionalCompanyIds = sSuppliers.getIntentionRegionalCompanyIds();
            if (StringUtils.isNotEmpty(intentionRegionalCompanyIds)) {
                String[] intentionRegionalCompanyIdArr = intentionRegionalCompanyIds.split(",");
                String intentionRegionalCompanyNames = sRegionalCompanyService.getRegionalCompanyNames(intentionRegionalCompanyIdArr);
                suppliersVOInfo.setIntentionRegionalCompanyNames(intentionRegionalCompanyNames);
            }

            //服务地区公司
//            String serviceRegionalCompanyIds = sSuppliers.getServiceRegionalCompanyIds();
            String serviceRegionalCompanyIds = extSSupplierRcRelateMapper.getQualifiedCompIds(SupplierBigStatusEnum.QUALIFIED.getCode() + "", id);
            if (StringUtils.isNotEmpty(serviceRegionalCompanyIds)) {
                String[] serviceRegionalCompanyIdArr = serviceRegionalCompanyIds.split(",");
                String serviceRegionalCompanyNames = sRegionalCompanyService.getRegionalCompanyNames(serviceRegionalCompanyIdArr);
                suppliersVOInfo.setServiceRegionalCompanyNames(serviceRegionalCompanyNames);
                suppliersVOInfo.setServiceRegionalCompanyIds(serviceRegionalCompanyIds);
            }
            suppliersVO.setSuppliersVO(suppliersVOInfo);

            EntityWrapper wrapper = new EntityWrapper<>();
            wrapper.orderBy(" create_date ", false);
            //根据suppliers_id查询供方信息-资质等级
            SSupplierQualificationGrade sSupplierQualificationGrade = new SSupplierQualificationGrade();
            sSupplierQualificationGrade.setSuppliersId(id);
            sSupplierQualificationGrade.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierQualificationGrade);
            List<SSupplierQualificationGrade> sSupplierQualificationGradels = sSupplierQualificationGradeService.selectList(wrapper);
            List<SuppliersQualificationGradeVO> suppliersQualificationGradeVOls = ListObjCopyUtil.copyTo(sSupplierQualificationGradels, SuppliersQualificationGradeVO.class);
//			List<SuppliersQualificationGradeVO> suppliersQualificationGradeVOls=sSupplierQualificationGradeService.selectObjs(wrapper);
            suppliersVO.setLstSuppliersQualificationGradeVO(suppliersQualificationGradeVOls);

            //根据suppliers_id查询供方信息-股东
            SSupplierStockholder sSupplierStockholder = new SSupplierStockholder();
            sSupplierStockholder.setSuppliersId(id);
            sSupplierStockholder.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierStockholder);
            List<SSupplierStockholder> sSupplierStockholderls = sSupplierStockholderService.selectList(wrapper);
            List<SuppliersStockHolderVO> suppliersStockHolderVOls = ListObjCopyUtil.copyTo(sSupplierStockholderls, SuppliersStockHolderVO.class);
//			List<SuppliersStockHolderVO> SuppliersStockHolderVOls=sSupplierStockholderService.selectObjs(wrapper);
            //前端需求---当没有股东时添加一个空的股东对象
            if (suppliersStockHolderVOls == null || suppliersStockHolderVOls.size() == 0) {
                SuppliersStockHolderVO suppliersStockHolderVO = new SuppliersStockHolderVO();
                suppliersStockHolderVOls = new ArrayList<>();
                suppliersStockHolderVOls.add(suppliersStockHolderVO);
            }
            suppliersVO.setLstSuppliersStockHolderVO(suppliersStockHolderVOls);

            //根据suppliers_id查询供方信息-联系方式
            SSupplierContactInfo sSupplierContactInfo = new SSupplierContactInfo();
            sSupplierContactInfo.setSuppliersId(id);
            sSupplierContactInfo.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierContactInfo);
            List<SSupplierContactInfo> sSupplierContactInfols = sSupplierContactInfoService.selectList(wrapper);
            List<SuppliersContactInfoVO> suppliersContactInfoVOls = ListObjCopyUtil.copyTo(sSupplierContactInfols, SuppliersContactInfoVO.class);
//			List<SuppliersContactInfoVO> suppliersContactInfoVOls=sSupplierContactInfoService.selectObjs(wrapper);
            //前端需求--当没有主联系人时返回值添加一个空的主联系人
            boolean existMain = false;
            ArrayList suppliersContactInfoVOlsCopy = new ArrayList<>(suppliersContactInfoVOls);
            for (int i = suppliersContactInfoVOls.size() - 1; i >= 0; i--) {
                SuppliersContactInfoVO suppliersContactInfoVO = suppliersContactInfoVOls.get(i);
                if (suppliersContactInfoVO.getMainFlag() != null && 1 == suppliersContactInfoVO.getMainFlag()) {
                    existMain = true;
                    suppliersContactInfoVOlsCopy.remove(suppliersContactInfoVO);
                    suppliersContactInfoVOlsCopy.add(0, suppliersContactInfoVO);
                }
            }
            if (!existMain) {
                if (suppliersContactInfoVOlsCopy == null) {
                    suppliersContactInfoVOlsCopy = new ArrayList();
                }
                SuppliersContactInfoVO suppliersContactInfoVO = new SuppliersContactInfoVO();
                suppliersContactInfoVO.setMainFlag(CommonConstants.MAIN_CONTACTS);//是否主联系人（0：否，1：是）
                suppliersContactInfoVOlsCopy.add(0, suppliersContactInfoVO);
            }
            suppliersVO.setLstSuppliersContactInfoVO(suppliersContactInfoVOlsCopy);

            //根据suppliers_id查询供方信息-获取信息类型
            SSupplierObtainInformation sSupplierObtainInformation = new SSupplierObtainInformation();
            sSupplierObtainInformation.setSuppliersId(id);
            sSupplierObtainInformation.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierObtainInformation);
            SuppliersObtainInformationVO suppliersObtainInformationVO = new SuppliersObtainInformationVO();
            sSupplierObtainInformation = sSupplierObtainInformationService.selectOne(wrapper);
            if (sSupplierObtainInformation != null)
                BeanUtils.copyProperties(sSupplierObtainInformation, suppliersObtainInformationVO);
            suppliersObtainInformationVO.setRecommenderTypeName(EnumConstant.recommenderType.getDesc(suppliersObtainInformationVO.getRecommenderType() + ""));
            suppliersVO.setSuppliersObtainInformationVO(suppliersObtainInformationVO);

            //根据suppliers_id查询供方信息-关联母公司信息
            SSupplierRelateParentCmpy sSupplierRelateParentCmpy = new SSupplierRelateParentCmpy();
            sSupplierRelateParentCmpy.setSuppliersId(id);
            sSupplierRelateParentCmpy.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierRelateParentCmpy);
            SuppliersRelateParentCmpyVO suppliersRelateParentCmpyVO = new SuppliersRelateParentCmpyVO();
            sSupplierRelateParentCmpy = sSupplierRelateParentCmpyService.selectOne(wrapper);
            if (sSupplierRelateParentCmpy != null)
                BeanUtils.copyProperties(sSupplierRelateParentCmpy, suppliersRelateParentCmpyVO);
            suppliersVO.setSuppliersRelateParentCmpyVO(suppliersRelateParentCmpyVO);

            //根据suppliers_id查询供方信息-银行账号
            SSupplierBankAccount sSupplierBankAccount = new SSupplierBankAccount();
            sSupplierBankAccount.setSuppliersId(id);
            sSupplierBankAccount.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierBankAccount);
            List<SSupplierBankAccount> lstSupplierBankAccount = sSupplierBankAccountService.selectList(wrapper);
            if (lstSupplierBankAccount != null) {
                suppliersVO.setLstSuppliersBankAccountVO(ListObjCopyUtil.copyTo(lstSupplierBankAccount, SuppliersBankAccountVO.class));
            }

            //根据suppliers_id查询供方信息-业务状况
            SSupplierBusinessSituation sSupplierBusinessSituation = new SSupplierBusinessSituation();
            sSupplierBusinessSituation.setSuppliersId(id);
            sSupplierBusinessSituation.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSupplierBusinessSituation);
            SuppliersBusinessSituationVO suppliersBusinessSituationVO = new SuppliersBusinessSituationVO();
            sSupplierBusinessSituation = sSupplierBusinessSituationService.selectOne(wrapper);
            if (sSupplierBusinessSituation != null)
                BeanUtils.copyProperties(sSupplierBusinessSituation, suppliersBusinessSituationVO);
            suppliersVO.setSuppliersBusinessSituationVO(suppliersBusinessSituationVO);

            //根据suppliers_id查询供方信息-近三年业绩 战略合作
            SSuppliersLastThreeAchieve sSuppliersLastThreeAchieveMajor = new SSuppliersLastThreeAchieve();
            sSuppliersLastThreeAchieveMajor.setSuppliersId(id);
            sSuppliersLastThreeAchieveMajor.setCooperativeType(CommonConstants.MAJOR_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
            sSuppliersLastThreeAchieveMajor.setSourceType(CommonConstants.EXTERNAL);//来源（0：外部，1：内部）
            sSuppliersLastThreeAchieveMajor.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSuppliersLastThreeAchieveMajor);
            List<SSuppliersLastThreeAchieve> sSuppliersLastThreeAchievelsMajor = sSuppliersLastThreeAchieveService.selectList(wrapper);
            List<SuppliersLastThreeMajorAchievenVO> suppliersLastThreeAchievenVOlsMajor = ListObjCopyUtil.copyTo(sSuppliersLastThreeAchievelsMajor, SuppliersLastThreeMajorAchievenVO.class);
            for (SuppliersLastThreeMajorAchievenVO suppliersLastThreeMajorAchievenVO : suppliersLastThreeAchievenVOlsMajor) {
                //根据suppliers_id、RelatedId查询供方信息-附件清单
                SAttachment sAttachment = new SAttachment();
                sAttachment.setFormId(id);
                sAttachment.setRelatedId(suppliersLastThreeMajorAchievenVO.getId());
                sAttachment.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
                wrapper.setEntity(sAttachment);
                List<SAttachment> sAttachmentls = sAttachmentService.selectList(wrapper);
                List<AttachmentVO> attachmentVOls = ListObjCopyUtil.copyTo(sAttachmentls, AttachmentVO.class);
                suppliersLastThreeMajorAchievenVO.setLstattachmentVO(attachmentVOls);
            }
            //前端需求
            if (suppliersLastThreeAchievenVOlsMajor == null || suppliersLastThreeAchievenVOlsMajor.size() == 0) {
                SuppliersLastThreeMajorAchievenVO suppliersLastThreeMajorAchievenVO = new SuppliersLastThreeMajorAchievenVO();
                suppliersLastThreeMajorAchievenVO.setLstattachmentVO(new ArrayList<>());
                suppliersLastThreeAchievenVOlsMajor = new ArrayList<>();
                suppliersLastThreeAchievenVOlsMajor.add(suppliersLastThreeMajorAchievenVO);
            }
            suppliersVO.setLstSuppliersLastThreeMajorAchievenVO(suppliersLastThreeAchievenVOlsMajor);

            //根据suppliers_id查询供方信息-近三年业绩 一般合作
            SSuppliersLastThreeAchieve sSuppliersLastThreeAchieveCommon = new SSuppliersLastThreeAchieve();
            sSuppliersLastThreeAchieveCommon.setSuppliersId(id);
            sSuppliersLastThreeAchieveCommon.setCooperativeType(CommonConstants.COMMON_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
            sSuppliersLastThreeAchieveCommon.setSourceType(CommonConstants.EXTERNAL);//来源（0：外部，1：内部）
            sSuppliersLastThreeAchieveCommon.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSuppliersLastThreeAchieveCommon);
            List<SSuppliersLastThreeAchieve> sSuppliersLastThreeAchievelsCommon = sSuppliersLastThreeAchieveService.selectList(wrapper);
            List<SuppliersLastThreeCommonAchievenVO> suppliersLastThreeAchievenVOlsCommon = ListObjCopyUtil.copyTo(sSuppliersLastThreeAchievelsCommon, SuppliersLastThreeCommonAchievenVO.class);
            for (SuppliersLastThreeCommonAchievenVO suppliersLastThreeCommonAchievenVO : suppliersLastThreeAchievenVOlsCommon) {
                //根据suppliers_id、RelatedId查询供方信息-附件清单
                SAttachment sAttachment = new SAttachment();
                sAttachment.setFormId(id);
                sAttachment.setRelatedId(suppliersLastThreeCommonAchievenVO.getId());
                sAttachment.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
                wrapper.setEntity(sAttachment);
                List<SAttachment> sAttachmentls = sAttachmentService.selectList(wrapper);
                List<AttachmentVO> attachmentVOls = ListObjCopyUtil.copyTo(sAttachmentls, AttachmentVO.class);
                suppliersLastThreeCommonAchievenVO.setLstattachmentVO(attachmentVOls);
            }
            //前端需求
            if (suppliersLastThreeAchievenVOlsCommon == null || suppliersLastThreeAchievenVOlsCommon.size() == 0) {
                SuppliersLastThreeCommonAchievenVO suppliersLastThreeCommonAchievenVO = new SuppliersLastThreeCommonAchievenVO();
                suppliersLastThreeCommonAchievenVO.setLstattachmentVO(new ArrayList<>());
                suppliersLastThreeAchievenVOlsCommon = new ArrayList<>();
                suppliersLastThreeAchievenVOlsCommon.add(suppliersLastThreeCommonAchievenVO);
            }
            suppliersVO.setLstSuppliersLastThreeCommonAchievenVO(suppliersLastThreeAchievenVOlsCommon);

            //根据suppliers_id查询供方信息-近三年业绩 内部业绩
            SSuppliersLastThreeAchieve sSuppliersLastThreeAchieve = new SSuppliersLastThreeAchieve();
            sSuppliersLastThreeAchieve.setSuppliersId(id);
            sSuppliersLastThreeAchieve.setSourceType(CommonConstants.INNER);//来源（0：外部，1：内部）
            sSuppliersLastThreeAchieve.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sSuppliersLastThreeAchieve);
            List<SSuppliersLastThreeAchieve> sSuppliersLastThreeAchievels = sSuppliersLastThreeAchieveService.selectList(wrapper);
            List<SuppliersLastThreeAchievenVO> suppliersLastThreeAchievenVOls = ListObjCopyUtil.copyTo(sSuppliersLastThreeAchievels, SuppliersLastThreeAchievenVO.class);
            for (SuppliersLastThreeAchievenVO suppliersLastThreeAchievenVO : suppliersLastThreeAchievenVOls) {
                suppliersLastThreeAchievenVO.setContactStatusName(ContactStatusEnum.getDesc(suppliersLastThreeAchievenVO.getContactStatus()));
            }
//            List<SuppliersLastThreeAchievenVO> suppliersLastThreeAchievenVOlsCopy=new ArrayList<>();
//            for (SuppliersLastThreeAchievenVO suppliersLastThreeAchievenVO : suppliersLastThreeAchievenVOls) {
//                //根据suppliers_id、RelatedId查询供方信息-附件清单
//                SAttachment sAttachment = new SAttachment();
//                sAttachment.setFormId(id);
//                sAttachment.setRelatedId(suppliersLastThreeAchievenVO.getId());
//                wrapper.setEntity(sAttachment);
//                List<SAttachment> sAttachmentls = sAttachmentService.selectList(wrapper);
//                List<AttachmentVO> attachmentVOls = ListObjCopyUtil.copyTo(sAttachmentls, AttachmentVO.class);
//                suppliersLastThreeAchievenVO.setLstattachmentVO(attachmentVOls);
//                if(suppliersLastThreeAchievenVO.getCooperativeType()==CommonConstants.MAJOR_COOPRATIVE){
//                    suppliersLastThreeAchievenVOlsCopy.add(0,suppliersLastThreeAchievenVO);
//                }else{
//                    suppliersLastThreeAchievenVOlsCopy.add(suppliersLastThreeAchievenVO);
//                }
//            }
            suppliersVO.setLstSuppliersInnerLastThreeAchievenVO(suppliersLastThreeAchievenVOls);

            //根据suppliers_id查询供方信息-附件清单
            SAttachment sAttachment = new SAttachment();
            sAttachment.setFormId(id);
            sAttachment.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapper.setEntity(sAttachment);
            List<SAttachment> sAttachmentls = sAttachmentService.selectList(wrapper);
            List<AttachmentVO> attachmentVOls = ListObjCopyUtil.copyTo(sAttachmentls, AttachmentVO.class);
            Map<Integer, List<AttachmentVO>> mapAttachmentVO = new HashMap<>();
            for (AttachmentVO attachmentVO : attachmentVOls) {
                if (AttachmentTypeEnum.ATTACHMENT_TYPE_1.getCode() == attachmentVO.getAttachmentType() ||//过滤附件类型1：供方三年业绩合同附件
                        AttachmentTypeEnum.ATTACHMENT_TYPE_13.getCode() == attachmentVO.getAttachmentType())
                    continue;//过滤附件类型13：供方考察报告附件
                List<AttachmentVO> ls = mapAttachmentVO.get(Integer.valueOf(attachmentVO.getAttachmentType()));
                if (ls == null) ls = new ArrayList<AttachmentVO>();
                ls.add(attachmentVO);
                mapAttachmentVO.put(Integer.valueOf(attachmentVO.getAttachmentType()), ls);
            }
            suppliersVO.setMapAttachmentVOs(mapAttachmentVO);

            //根据suppliers_id查询供方信息-考察报告
            List<ExtSSuppliersInspection> sSuppliersInspectionExtls = sSuppliersInspectionService.getListBySupplierId(id);
            List<SuppliersInspectionVO> sSuppliersInspectionls = ListObjCopyUtil.copyTo(sSuppliersInspectionExtls, SuppliersInspectionVO.class);
            for (SuppliersInspectionVO suppliersInspectionVO : sSuppliersInspectionls) {
                if (StringUtils.isNotEmpty(suppliersInspectionVO.getInspectionMemberUserIds())) {
                    String names = sysUserService.getSysUserNameByIds(suppliersInspectionVO.getInspectionMemberUserIds());
                    if (StringUtils.isNotEmpty(names)) {
                        suppliersInspectionVO.setInspectionMemberUserNames(names);
                    }
                    //供方分类
                    String rcsupplierCategoryIds = suppliersInspectionVO.getSupplierCategoryIds();
                    if (StringUtils.isNotEmpty(rcsupplierCategoryIds)) {
                        String[] supplierCategoryIdArr = rcsupplierCategoryIds.split(",");
                        String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                        suppliersInspectionVO.setSupplierCategoryNames(supplierCategoryNames);
                    }
                    //供方分类
                    String supplierCategoryActualIds = suppliersInspectionVO.getSupplierCategoryActualIds();
                    if (StringUtils.isNotEmpty(supplierCategoryActualIds)) {
                        String[] supplierCategoryIdArr = supplierCategoryActualIds.split(",");
                        String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                        suppliersInspectionVO.setSupplierCategoryActualNames(supplierCategoryNames);
                    }
                    //根据suppliers_id、RelatedId查询供方信息-附件清单
                }
                SAttachment obj = new SAttachment();
                obj.setFormId(id);
                obj.setRelatedId(suppliersInspectionVO.getId());
                obj.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
                wrapper.setEntity(obj);
                List<SAttachment> attachmentList = sAttachmentService.selectList(wrapper);
                List<AttachmentVO> attachmentVOList = ListObjCopyUtil.copyTo(attachmentList, AttachmentVO.class);
                suppliersInspectionVO.setLstAttachmentVO(attachmentVOList);
//                EntityWrapper wrapperObj = new EntityWrapper<>();
//                SSuppliersInspectionScore sSuppliersInspectionScore=new SSuppliersInspectionScore();
//                sSuppliersInspectionScore.setSuppliersInspectionId(suppliersInspectionVO.getId());
//                wrapperObj.setEntity(sSuppliersInspectionScore);
//                List<SSuppliersInspectionScore> ls=sSuppliersInspectionScoreService.selectList(wrapperObj);
//                List<SuppliersInspectionScoreResponseVO> lsVo=ListObjCopyUtil.copyTo(ls, SuppliersInspectionScoreResponseVO.class);
//                suppliersInspectionVO.setLstSuppliersInspectionScoreResponseVO(lsVo);
            }
//			List<SuppliersInspectionVO> suppliersInspectionVOls=sSuppliersInspectionService.selectObjs(wrapper);
            suppliersVO.setLstSuppliersInspectionVO(sSuppliersInspectionls);

            //根据suppliers_id查询供方信息-审批历程
            List<ExtSHistoryComment> sHistoryCommentls = extSHistoryCommentMapper.getCommentList(id, HistoryCommentTypeEnum.INTERNET.getCode());
            List<HistoryCommentVO> historyCommentVOls = ListObjCopyUtil.copyTo(sHistoryCommentls, HistoryCommentVO.class);
//			List<HistoryCommentVO> historyCommentVOls=sHistoryCommentService.selectObjs(wrapper);
            suppliersVO.setLstHistoryCommentVO(historyCommentVOls);

            //根据suppliers_id查询供方信息-外网审核记录
            List<ExtSHistoryComment> sHistoryCommentExtLs = extSHistoryCommentMapper.getCommentList(id, HistoryCommentTypeEnum.INTRANET.getCode());
            List<HistoryCommentVO> historyCommentVOExtls = ListObjCopyUtil.copyTo(sHistoryCommentExtLs, HistoryCommentVO.class);
            suppliersVO.setLstHistoryCommentOutVO(historyCommentVOExtls);

            //变更历史
            List<ExtSSuppliersModifiedHistory> ls = sSuppliersModifiedHistoryService.getListBySupplerId(id);
            List<SuppliersModifiedHistoryVO> lsVo = ListObjCopyUtil.copyTo(ls, SuppliersModifiedHistoryVO.class);
            suppliersVO.setSuppliersModifiedHistoryVO(lsVo);

            hResult = new RestReturnResult<SuppliersDetailVO>(CommonConstants.SUCCESS, suppliersVO);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
        return hResult;
    }

    @Override
    public SSuppliers getByCompanyName(String companyName) {
        List<SSuppliers> sSuppliers = selectList(new EntityWrapper<SSuppliers>().eq("company_name", companyName));
        if (CollectionUtils.isNotEmpty(sSuppliers))
            return sSuppliers.get(0);
        return null;
    }

    @Override
    public boolean isExistCompanyName(String companyName, String id) {
        SSuppliers sSuppliers = getByCompanyName(companyName);
        if (sSuppliers != null && !sSuppliers.getId().equals(id)) {
            return true;
        }
        return false;
    }

    /***
     * 外网供方新增
     * @param suppliersDetailVo
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackForClassName = {"RuntimeException", "Exception"})
    public RestReturnResult<Object> outerSaveSuppliers(SuppliersDetailVO suppliersDetailVo) {
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, suppliersDetailVo, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
        try {
            String userId = "";
            SSuppliers sSuppliers = new SSuppliers();
            if (isExistCompanyName(suppliersDetailVo.getSuppliersVO().getCompanyName(), suppliersDetailVo.getSuppliersVO().getId())) {
                return new RestReturnResult(CommonConstants.FAIL, "注册名称已存在");
            }
            if (suppliersDetailVo.getSuppliersVO().getCreditLicenseCodeFlag() == 1) {//信用代码或营业执照号（1：统一社会信用代码， 2：营业执照号）
                sSuppliers.setSocialCreditCode(suppliersDetailVo.getSuppliersVO().getSocialCreditCode());
            } else {
                sSuppliers.setBusinessLicenseNumber(suppliersDetailVo.getSuppliersVO().getBusinessLicenseNumber());
            }
            Integer count = extSSuppliersMapper.findSupplierCount(sSuppliers);
            if (count != null && count > 0) {
                return new RestReturnResult(CommonConstants.FAIL, "营业执照号/统一社会信用代码 已存在");
            }
            UserRequestVO userVO = suppliersDetailVo.getUserRequestVO();
            if (userVO != null && StringUtils.isNotEmpty(userVO.getUserName())) {
                SysUser sysUser = sysUserService.getSysUserByUserName(userVO.getUserName());
                if (sysUser == null) {
                    /*String piccode = redisDBHelper.hashGet(CommonConstants.SMSCODE + userVO.getUserName(), userVO.getUserName());
                    if (StringUtils.isNotEmpty(piccode) && StringUtils.isNotEmpty(userVO.getVerificationCode())) {
                        if (!piccode.toUpperCase().equals(userVO.getVerificationCode().toUpperCase())) {
                            return new RestReturnResult(CommonConstants.FAIL, "验证码错误");
                        }
                    } else {
                        return new RestReturnResult(CommonConstants.FAIL, "验证码错误");
                    }*/
                    RestReturnResult<SysUser> result = sysUserService.saveUserRequestVo(userVO);
                    if (result == null || CommonConstants.FAIL.equals(result.getCode())) {
                        throw new RuntimeException("系统错误!");
                    }
                    //保存or更新供方基本情况 设置用户id
                    sSuppliers = new SSuppliers();
                    userId = result.getData().getId();
                    sSuppliers.setSysUserId(result.getData().getId());
                } else {
                    throw new RuntimeException("用户名已存在");
                }
            } else {
                throw new RuntimeException("用户数据为空");
            }
            //保存基本情况
            BeanUtils.copyProperties(suppliersDetailVo.getSuppliersVO(), sSuppliers);
            sSuppliers.setId(IdGen.uuid());

            sSuppliers.setBaseFeilds(userId, null, 0, true);
            sSuppliers.setRegisterStatus(Integer.parseInt(RegisterStatusEnum.STORE_APPROVE_ING.getCode()));
            sSuppliers.setSupplierStatus(Integer.parseInt(SupplierStatusEnum.QUALIFICATION_INSPECTION.getCode()));
            sSuppliers.setSupplierBigStatus(SupplierBigStatusEnum.POTENTIAL.getCode());
            sSuppliers.setRegisterTime(new Date());

            //企业编码  时间戳13位
//            sSuppliers.setCompanyCode(System.currentTimeMillis()+"");
            super.insert(sSuppliers);

            //保存操作历史
            boolean historyCommentFlag = saveSHistoryComment(sSuppliers.getId(), userId);
            if (!historyCommentFlag) {
                throw new RuntimeException("系统错误!");
            }


            String intentionRegionalCompanyIds = suppliersDetailVo.getSuppliersVO().getIntentionRegionalCompanyIds();
            if (StringUtils.isNotEmpty(intentionRegionalCompanyIds)) {
                String[] intentionRegionalCompanyIdArr = intentionRegionalCompanyIds.split(",");
                List<SSupplierRcRelate> sSupplierRcRelateLs = new ArrayList<>();
                //List<SMyDeals> sMyDealsLs = new ArrayList<>();
                for (String intentionRegionalCompanyId : intentionRegionalCompanyIdArr) {
                    SSupplierRcRelate obj = new SSupplierRcRelate();
                    obj.setId(IdGen.uuid());
                    obj.setSuppliersId(sSuppliers.getId());
                    obj.setRegionalCompanyId(intentionRegionalCompanyId);
                    obj.setSupplierCategoryIds(sSuppliers.getSupplierCategoryIds());
                    obj.setSupplierServiceCategoryIds(sSuppliers.getSupplierServiceCategoryIds());
                    obj.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.QUALIFICATION_INSPECTION.getCode()));
                    obj.setSupplierBigStatus(SupplierBigStatusEnum.POTENTIAL.getCode());
                    obj.setBaseFeilds(userId, null, 0, true);
                    obj.setSupplierSource(SupplierSourceEnum.ADD.getCode());
                    sSupplierRcRelateLs.add(obj);

//                    //外网新增供方给意向地区公司发送待办
//                        SRegionalCompany sRegionalCompany = sRegionalCompanyService.selectById(intentionRegionalCompanyId);
//                        if(sRegionalCompany!=null&&StringUtils.isNotEmpty(sRegionalCompany.getSupplierMngUsers())){
//                            String[] mngUserIdArr=sRegionalCompany.getSupplierMngUsers().split(",");
//                            if(mngUserIdArr!=null&&mngUserIdArr.length>0){
//                                for(String mngUserId:mngUserIdArr){
//                                    SMyDeals sMyDeals = new SMyDeals();
//                                    sMyDeals.setId(IdGen.uuid());
//                                    sMyDeals.setUserId(mngUserId);
//                                    sMyDeals.setDealEndTime(new Date());
//                                    String titleTemplate = sCommentConfigService.getValueByCode(CommentConfigEnum.MY_DEAL_TEMPLATE.getCode());
//                                    String title = MessageFormat.format(titleTemplate, MyDealSubTypeEnum.QUALIFICATION_INSPECTION.getDesc(), sSuppliers.getCompanyName()+MyDealSubTypeEnum.QUALIFICATION_INSPECTION.getDesc());
//                                    sMyDeals.setDealTitle(title);
//                                    sMyDeals.setDealType(DealTypeEnum.SUPPLIERS.getCode());//类型（1：供方，2：采购）
//                                    sMyDeals.setRelatedId(sSuppliers.getId());
//                                    sMyDeals.setSubRelatedId(obj.getId());
//                                    sMyDeals.setActionType(MyDealActionTypeEnum.QUALIFICATION_INSPECTION.getCode());
//                                    sMyDeals.setDealSubType(MyDealSubTypeEnum.QUALIFICATION_INSPECTION.getCode());
//                                    sMyDeals.setBaseFeilds(userId, null, 0, true);
//                                    sMyDeals.setDoneFlag(CommonConstants.NO_INTEGER);
//                                    sMyDealsLs.add(sMyDeals);
//                                }
//                            }
//                        }
                }
                if (sSupplierRcRelateLs != null && sSupplierRcRelateLs.size() > 0)
                    sSupplierRcRelateService.insertBatch(sSupplierRcRelateLs);
                //if(sMyDealsLs!=null&&sMyDealsLs.size()>0)sMyDealsService.insertBatch(sMyDealsLs);
            }

            //供方基本情况-供方分类关系表保存
            String supplierCategoryIds = suppliersDetailVo.getSuppliersVO().getSupplierCategoryIds();
            if (StringUtils.isNotEmpty(supplierCategoryIds)) {
                String[] supplierCategoryIdArr = supplierCategoryIds.split(",");
                List<SSupplierCategoryRelate> sSupplierCategoryRelateLs = new ArrayList<>();
                for (String supplierCategoryId : supplierCategoryIdArr) {
                    SSupplierCategoryRelate obj = new SSupplierCategoryRelate();
                    obj.setId(IdGen.uuid());
                    obj.setSuppliersId(sSuppliers.getId());
                    obj.setCategoryId(supplierCategoryId);
                    obj.setBaseFeilds(userId, null, 0, true);
                    sSupplierCategoryRelateLs.add(obj);
                }
                if (sSupplierCategoryRelateLs != null && sSupplierCategoryRelateLs.size() > 0)
                    sSupplierCategoryRelateService.insertBatch(sSupplierCategoryRelateLs);
            }

            //保存供方信息-资质等级
            if (suppliersDetailVo.getLstSuppliersQualificationGradeVO() != null &&
                    suppliersDetailVo.getLstSuppliersQualificationGradeVO().size() != 0) {
                List<SSupplierQualificationGrade> lsSSupplierQualificationGrade = ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersQualificationGradeVO(), SSupplierQualificationGrade.class);
                for (SSupplierQualificationGrade objNew : lsSSupplierQualificationGrade) {
                    objNew.setId(IdGen.uuid());
                    objNew.setBaseFeilds(userId, null, 0, true);
                    objNew.setSuppliersId(sSuppliers.getId());
                }
                if (lsSSupplierQualificationGrade != null && lsSSupplierQualificationGrade.size() > 0)
                    sSupplierQualificationGradeService.insertBatch(lsSSupplierQualificationGrade);
            }

            //保存供方基本情况-股东
            if (suppliersDetailVo.getLstSuppliersStockHolderVO() != null &&
                    suppliersDetailVo.getLstSuppliersStockHolderVO().size() != 0) {
                List<SSupplierStockholder> lsSSupplierStockholder = ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersStockHolderVO(), SSupplierStockholder.class);
                for (SSupplierStockholder objNew : lsSSupplierStockholder) {
                    objNew.setId(IdGen.uuid());
                    objNew.setBaseFeilds(userId, null, 0, true);
                    objNew.setSuppliersId(sSuppliers.getId());
                }
                if (lsSSupplierStockholder != null && lsSSupplierStockholder.size() > 0)
                    sSupplierStockholderService.insertBatch(lsSSupplierStockholder);
            }

            //保存供方基本情况-联系方式
            if (suppliersDetailVo.getLstSuppliersContactInfoVO() != null &&
                    suppliersDetailVo.getLstSuppliersContactInfoVO().size() != 0) {
                List<SSupplierContactInfo> lsSSupplierContactInfo = ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersContactInfoVO(), SSupplierContactInfo.class);
                for (SSupplierContactInfo objNew : lsSSupplierContactInfo) {
                    objNew.setId(IdGen.uuid());
                    objNew.setBaseFeilds(userId, null, 0, true);
                    objNew.setSuppliersId(sSuppliers.getId());
                }
                if (lsSSupplierContactInfo != null && lsSSupplierContactInfo.size() > 0)
                    sSupplierContactInfoService.insertBatch(lsSSupplierContactInfo);
            }

            //保存供方基本情况--获取信息类型
            if (suppliersDetailVo.getSuppliersObtainInformationVO() != null) {
                SSupplierObtainInformation sSupplierObtainInformation = new SSupplierObtainInformation();
                BeanUtils.copyProperties(suppliersDetailVo.getSuppliersObtainInformationVO(), sSupplierObtainInformation);
                sSupplierObtainInformation.setSuppliersId(sSuppliers.getId());
                sSupplierObtainInformation.setId(IdGen.uuid());
                sSupplierObtainInformation.setBaseFeilds(userId, null, 0, true);
                sSupplierObtainInformationService.insert(sSupplierObtainInformation);
            }

            //保存供方基本情况--关联母公司信息
            if (suppliersDetailVo.getSuppliersRelateParentCmpyVO() != null) {
                SSupplierRelateParentCmpy sSupplierRelateParentCmpy = new SSupplierRelateParentCmpy();
                if (suppliersDetailVo.getSuppliersRelateParentCmpyVO().getHasRelateParentCompany() != null &&
                        suppliersDetailVo.getSuppliersRelateParentCmpyVO().getHasRelateParentCompany() == CommonConstants.YES_INTEGER) {
                    BeanUtils.copyProperties(suppliersDetailVo.getSuppliersRelateParentCmpyVO(), sSupplierRelateParentCmpy);
                } else {
                    sSupplierRelateParentCmpy.setId(suppliersDetailVo.getSuppliersRelateParentCmpyVO().getId());
                    sSupplierRelateParentCmpy.setHasRelateParentCompany(CommonConstants.NO_INTEGER);
                }
                sSupplierRelateParentCmpy.setSuppliersId(sSuppliers.getId());
                sSupplierRelateParentCmpy.setId(IdGen.uuid());
                sSupplierRelateParentCmpy.setBaseFeilds(userId, null, 0, true);
                sSupplierRelateParentCmpyService.insert(sSupplierRelateParentCmpy);
            }

            //保存供方基本情况--业务状况
            if (suppliersDetailVo.getSuppliersBusinessSituationVO() != null) {
                SSupplierBusinessSituation sSupplierBusinessSituation = new SSupplierBusinessSituation();
                BeanUtils.copyProperties(suppliersDetailVo.getSuppliersBusinessSituationVO(), sSupplierBusinessSituation);
                sSupplierBusinessSituation.setSuppliersId(sSuppliers.getId());
                sSupplierBusinessSituation.setId(IdGen.uuid());
                sSupplierBusinessSituation.setBaseFeilds(userId, null, 0, true);
                sSupplierBusinessSituationService.insert(sSupplierBusinessSituation);
            }

            //保存方近三年业绩-战略合作+一般合作
            List<SuppliersLastThreeMajorAchievenVO> lstSuppliersLastThreeMajorAchievenVO = suppliersDetailVo.getLstSuppliersLastThreeMajorAchievenVO();
            List<SuppliersLastThreeCommonAchievenVO> lstSuppliersLastThreeCommonAchievenVO = suppliersDetailVo.getLstSuppliersLastThreeCommonAchievenVO();
            if (lstSuppliersLastThreeMajorAchievenVO == null) lstSuppliersLastThreeMajorAchievenVO = new ArrayList<>();
            if (lstSuppliersLastThreeCommonAchievenVO == null)
                lstSuppliersLastThreeCommonAchievenVO = new ArrayList<>();
            Map<Integer, List<AttachmentVO>> attachmentVOmap = suppliersDetailVo.getMapAttachmentVOs();
            if (attachmentVOmap == null) attachmentVOmap = new HashMap<Integer, List<AttachmentVO>>();
            List<AttachmentVO> lstAttachment = new ArrayList<>();
            for (int i = lstSuppliersLastThreeMajorAchievenVO.size() - 1; i >= 0; i--) {
                SuppliersLastThreeMajorAchievenVO obj = lstSuppliersLastThreeMajorAchievenVO.get(i);
                if (StringUtils.isEmpty(obj.getCooperativeUnitName())) {
                    lstSuppliersLastThreeMajorAchievenVO.remove(obj);
                }
                obj.setCooperativeType(CommonConstants.MAJOR_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
                //保存三年业绩附件
                List<AttachmentVO> ls = obj.getLstattachmentVO();
                if (ls != null && ls.size() > 0) {
                    for (AttachmentVO attachmentVO : ls) {
                        attachmentVO.setFormId(sSuppliers.getId());
                        attachmentVO.setRelatedId(obj.getId());
                        attachmentVO.setAttachmentType(1);
                    }
                    lstAttachment.addAll(ls);
                }
            }
            for (int i = lstSuppliersLastThreeCommonAchievenVO.size() - 1; i >= 0; i--) {
                SuppliersLastThreeCommonAchievenVO obj = lstSuppliersLastThreeCommonAchievenVO.get(i);
                if (StringUtils.isEmpty(obj.getCooperativeUnitName())) {
                    lstSuppliersLastThreeCommonAchievenVO.remove(obj);
                }
                obj.setCooperativeType(CommonConstants.COMMON_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
                List<AttachmentVO> ls = obj.getLstattachmentVO();
                if (ls != null && ls.size() > 0) {
                    for (AttachmentVO attachmentVO : ls) {
                        attachmentVO.setFormId(sSuppliers.getId());
                        attachmentVO.setRelatedId(obj.getId());
                        attachmentVO.setAttachmentType(1);
                    }
                    lstAttachment.addAll(ls);
                }
            }
            if (lstAttachment != null && lstAttachment.size() > 0)
                attachmentVOmap.put(1, lstAttachment);//添加1：供方三年业绩合同附件
            suppliersDetailVo.setMapAttachmentVOs(attachmentVOmap);

            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieve = new ArrayList<>();
            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveMajor = ListObjCopyUtil.copyTo(lstSuppliersLastThreeMajorAchievenVO, SSuppliersLastThreeAchieve.class);
            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveCommon = ListObjCopyUtil.copyTo(lstSuppliersLastThreeCommonAchievenVO, SSuppliersLastThreeAchieve.class);
            lsSSuppliersLastThreeAchieve.addAll(lsSSuppliersLastThreeAchieveMajor);
            lsSSuppliersLastThreeAchieve.addAll(lsSSuppliersLastThreeAchieveCommon);
            if (lsSSuppliersLastThreeAchieve != null && lsSSuppliersLastThreeAchieve.size() != 0) {
                for (SSuppliersLastThreeAchieve objNew : lsSSuppliersLastThreeAchieve) {
                    objNew.setSuppliersId(sSuppliers.getId());
                    objNew.setSourceType(CommonConstants.EXTERNAL);
                    objNew.setId(IdGen.uuid());
                    objNew.setBaseFeilds(userId, null, 0, true);
                }
                sSuppliersLastThreeAchieveService.insertOrUpdateAllColumnBatch(lsSSuppliersLastThreeAchieve);
            }

            //保存附件
            if (suppliersDetailVo.getMapAttachmentVOs() != null &&
                    suppliersDetailVo.getMapAttachmentVOs().size() != 0) {
                Map<Integer, List<AttachmentVO>> map = suppliersDetailVo.getMapAttachmentVOs();
                List<SAttachment> lsSAttachment = new ArrayList<>();
                for (List<AttachmentVO> ls : map.values()) {
                    lsSAttachment.addAll(ListObjCopyUtil.copyTo(ls, SAttachment.class));
                }
                for (SAttachment objNew : lsSAttachment) {
                    objNew.setId(IdGen.uuid());
                    objNew.setBaseFeilds(userId, null, 0, true);
                    objNew.setFormId(sSuppliers.getId());
                }
                if (lsSAttachment != null && lsSAttachment.size() > 0)
                    sAttachmentService.insertOrUpdateAllColumnBatch(lsSAttachment);
            }


            //保存or更新供方基本情况--银行账号
            String supplierId = sSuppliers.getId();
            EntityWrapper wrapperSSupplierBankAccount = new EntityWrapper<>();
            SSupplierBankAccount entrySSupplierBankAccount = new SSupplierBankAccount();
            entrySSupplierBankAccount.setSuppliersId(sSuppliers.getId());
            entrySSupplierBankAccount.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierBankAccount.setEntity(entrySSupplierBankAccount);
            List<SSupplierBankAccount> oldLstBankAccount = sSupplierBankAccountService.selectList(wrapperSSupplierBankAccount);
            List<SuppliersBankAccountVO> lstBankAccountVO = suppliersDetailVo.getLstSuppliersBankAccountVO();
            List<String> bankAccountIds = lstBankAccountVO.stream().map(SuppliersBankAccountVO::getId).collect(Collectors.toList());
            if (lstBankAccountVO != null && lstBankAccountVO.size() > 0) {
                lstBankAccountVO.forEach(item -> {

                    SSupplierBankAccount bankAccountVo = new SSupplierBankAccount();
                    bankAccountVo.setSuppliersId(supplierId);
                    bankAccountVo.setAccountNumber(item.getAccountNumber());
                    bankAccountVo.setAccountType(item.getAccountType());
                    bankAccountVo.setBankName(item.getBankName());
                    bankAccountVo.setBankNumber(item.getBankNumber());
                    bankAccountVo.setId(item.getId());
                    bankAccountVo.setBaseFeilds(UserUtils.getCurrentUserId(), "", CommonConstants.DEL_FLAG_NORMAL, StringUtils.isEmpty(item.getId()));
                    sSupplierBankAccountService.insertOrUpdate(bankAccountVo);
                });
            }

            if (oldLstBankAccount != null && oldLstBankAccount.size() > 0) {
                //数据库存在，但提交的数据不存在了，则进行逻辑删除操作
                List<SSupplierBankAccount> delList = oldLstBankAccount.stream().filter(item -> !bankAccountIds.contains(item.getId())).collect(Collectors.toList());
                delList.forEach(item -> {
                    item.setBaseFeilds(UserUtils.getCurrentUserId(), "", CommonConstants.DEL_FLAG_DELETE, false);
                    sSupplierBankAccountService.updateById(item);
                });

            }

            hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS, "保存成功");
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("系统错误");
        }
        return hResult;
    }


    /***
     * 外网供方更新
     * @param suppliersDetailVo
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackForClassName = {"RuntimeException", "Exception"})
    public RestReturnResult<Object> outerUpdateSuppliers(HttpServletRequest request, SuppliersDetailVO suppliersDetailVo) {
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, suppliersDetailVo, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

        try {
            String userId = UserUtils.getOuterCurrentUserId();
            if (StringUtils.isEmpty(userId)) {
                return RestReturnResult.error();
            }

            if (isExistCompanyName(suppliersDetailVo.getSuppliersVO().getCompanyName(), suppliersDetailVo.getSuppliersVO().getId())) {
                return new RestReturnResult(CommonConstants.FAIL, "注册名称已存在");
            }
//            String userId="6126ef53a8c94dbaaf05a7fa14c02547";
            SSuppliers sSuppliers = new SSuppliers();
            SSupplierRcRelate sSupplierRcRelateStatus = new SSupplierRcRelate();
            //保存or更新供方基本情况
            BeanUtils.copyProperties(suppliersDetailVo.getSuppliersVO(), sSuppliers);
            if (StringUtils.isEmpty(sSuppliers.getId())) {
                sSuppliers.setId(IdGen.uuid());
            }
            SSuppliers sSuppliersOld = super.selectById(sSuppliers.getId());
            if (sSuppliersOld == null) {
                throw new RuntimeException("供方信息不存在");
            }
            sSuppliers.setBaseFeilds(userId, null, 0, false);

            if (sSuppliersOld.getModifiedFlag() != null && sSuppliersOld.getModifiedFlag() == CommonConstants.YES_INTEGER) {
                throw new RuntimeException("供方在修改审批中，请联系服务地区公司管理员进行审核");
            }

            //查询入库审批中意向地区公司数量
            EntityWrapper rcRelateWrapper = new EntityWrapper();
            SSupplierRcRelate rcRelateObj = new SSupplierRcRelate();
            rcRelateObj.setSuppliersId(sSuppliersOld.getId());
            rcRelateObj.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            rcRelateObj.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.STORE_APPROVE_ING.getCode()));
            rcRelateWrapper.setEntity(rcRelateObj);
            int countStoring = sSupplierRcRelateService.selectCount(rcRelateWrapper);
            if (countStoring > 0) {
                throw new RuntimeException("供方入库审批中，无法修改");
            }

            //查询合格意向地区公司
            List<ExtSSupplierRcRelate> lsSupplierRcRelate = extSSupplierRcRelateMapper.getCompanyListByStatus(SupplierBigStatusEnum.QUALIFIED.getCode() + "", sSuppliersOld.getId());
            if (suppliersDetailVo.getSuppliersVO().getCreditLicenseCodeFlag() == 1) {//信用代码或营业执照号（1：统一社会信用代码， 2：营业执照号）
                sSuppliers.setSocialCreditCode(suppliersDetailVo.getSuppliersVO().getSocialCreditCode());
            } else {
                sSuppliers.setBusinessLicenseNumber(suppliersDetailVo.getSuppliersVO().getBusinessLicenseNumber());
            }
            sSuppliers.setId(suppliersDetailVo.getSuppliersVO().getId());
            Integer count = extSSuppliersMapper.findSupplierCount(sSuppliers);
            if (count != null && count > 0) {
                throw new RuntimeException("营业执照号/统一社会信用代码 已存在");
            }
            //待修改改为资质审查 待修改为资质审查退回
            if (SupplierStatusEnum.PENDING_MODIFY.getCode().equals(sSuppliersOld.getSupplierStatus() + "")) {
                sSuppliers.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.QUALIFICATION_INSPECTION.getCode()));
                //退回修改再提交给退回操作人发待办
                String intentionRegionalCompanyIds = suppliersDetailVo.getSuppliersVO().getIntentionRegionalCompanyIds();
                if (StringUtils.isNotEmpty(intentionRegionalCompanyIds)) {
                    String[] intentionRegionalCompanyIdsArr = intentionRegionalCompanyIds.split(",");
                    ExtSMessages extSMessages = extSMessagesMapper.getLastOneMessage(userId, MessagesMsgTypeEnum.ANNOUNCEMENT_NOTICE.getCode());
                    if (intentionRegionalCompanyIdsArr != null && intentionRegionalCompanyIdsArr.length > 0 && StringUtils.isNotEmpty(extSMessages.getCreateBy())) {
//                            Integer index=extSRegionalCompanyMapper.checkMngUser(intentionRegionalCompanyIdsArr,extSMessages.getCreateBy());
                        if (StringUtils.isNotEmpty(extSMessages.getFlowFormId())) {
                            ExtSSupplierRcRelate extSSupplierRcRelate = extSSupplierRcRelateMapper.getExtId(extSMessages.getFlowFormId());
                            String mngUsers = extSSupplierRcRelate.getSupplierMngUsers();
                            String compyId = extSSupplierRcRelate.getRegionalCompanyId();
                            if (StringUtils.isNotEmpty(mngUsers) && StringUtils.isNotEmpty(compyId)) {
                                List<String> compyIdList = Arrays.asList(intentionRegionalCompanyIdsArr);
                                List<String> mngUserList = Arrays.asList(mngUsers.split(","));
                                if (compyIdList.contains(compyId) && mngUserList.contains(extSMessages.getCreateBy())) {
                                    SMyDeals sMyDeals = new SMyDeals();
                                    sMyDeals.setUserId(extSMessages.getCreateBy());
                                    sMyDeals.setDealEndTime(new Date());
                                    String titleTemplate = sCommentConfigService.getValueByCode(CommentConfigEnum.MY_DEAL_TEMPLATE.getCode());
                                    String title = MessageFormat.format(titleTemplate, MyDealSubTypeEnum.QUALIFICATION_INSPECTION.getDesc(), sSuppliers.getCompanyName() + MyDealSubTypeEnum.QUALIFICATION_INSPECTION.getDesc());
                                    sMyDeals.setDealTitle(title);
                                    sMyDeals.setDealType(DealTypeEnum.SUPPLIERS.getCode());//类型（1：供方，2：采购）
                                    sMyDeals.setRelatedId(sSuppliersOld.getId());
                                    sMyDeals.setSubRelatedId(extSMessages.getFlowFormId());
                                    sMyDeals.setActionType(MyDealActionTypeEnum.QUALIFICATION_INSPECTION.getCode());
                                    sMyDeals.setDealSubType(MyDealSubTypeEnum.QUALIFICATION_INSPECTION.getCode());
                                    sMyDeals.setBaseFeilds(userId, null, 0, true);
                                    sMyDeals.setDoneFlag(CommonConstants.NO_INTEGER);
                                    sMyDealsService.saveSMyDeals(sMyDeals);
                                }
                            }
                        }
                    }
                }
            }
            if (lsSupplierRcRelate != null && lsSupplierRcRelate.size() > 0) {
                sSupplierRcRelateStatus.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.QUALIFIED.getCode()));

                List<SMyDeals> sMyDealsLs = new ArrayList<>();
                //合格供方修改给合格地区公司发送待办
                for (ExtSSupplierRcRelate sSupplierRcRelate : lsSupplierRcRelate) {
                    String supplierMngUsers = sSupplierRcRelate.getSupplierMngUsers();
                    if (StringUtils.isNotEmpty(supplierMngUsers)) {
                        String[] mngUserIdArr = supplierMngUsers.split(",");
                        if (mngUserIdArr != null && mngUserIdArr.length > 0) {
                            for (String mngUserId : mngUserIdArr) {
                                SMyDeals sMyDeals = new SMyDeals();
                                sMyDeals.setUserId(mngUserId);
                                sMyDeals.setDealEndTime(new Date());
                                String titleTemplate = sCommentConfigService.getValueByCode(CommentConfigEnum.MY_DEAL_TEMPLATE.getCode());
                                String title = MessageFormat.format(titleTemplate, MyDealSubTypeEnum.SUPPLIERS_CHANGE.getDesc(), sSuppliers.getCompanyName() + MyDealSubTypeEnum.SUPPLIERS_CHANGE.getDesc());
                                sMyDeals.setDealTitle(title);
                                sMyDeals.setDealType(DealTypeEnum.SUPPLIERS.getCode());//类型（1：供方，2：采购）
                                sMyDeals.setRelatedId(sSuppliersOld.getId());
                                sMyDeals.setSubRelatedId(sSuppliersOld.getId());
                                sMyDeals.setActionType(MyDealActionTypeEnum.SUPPLIERS_CHANGE.getCode());
                                sMyDeals.setDealSubType(MyDealSubTypeEnum.SUPPLIERS_CHANGE.getCode());
                                sMyDeals.setBaseFeilds(userId, null, 0, true);
                                sMyDeals.setDoneFlag(CommonConstants.NO_INTEGER);
                                sMyDealsLs.add(sMyDeals);
                            }
                        }
                    }
                }
                if (sMyDealsLs != null && sMyDealsLs.size() > 0) sMyDealsService.insertBatch(sMyDealsLs);

                //合格供方改为修改中
                sSuppliers.setModifiedFlag(CommonConstants.YES_INTEGER);
                //合格供方修改
                SHistoryComment sHistoryComment = new SHistoryComment();
                sHistoryComment.setId(IdGen.uuid());
                sHistoryComment.setModelType(HistoryCommentModelTypeEnum.HistoryCommentModelType3.getCode());//功能模块（1：供方信息审核历程，2：供方现场考察组员意见，3：供方评估审核，
                sHistoryComment.setRelatedId(sSuppliersOld.getId());
                sHistoryComment.setSubRelatedId(sSuppliersOld.getId());
                sHistoryComment.setNodeName(sCommentConfigService.getValueByCode(CommentConfigEnum.SUPPLIER_EXTRANET_MODIFY_HISTORY_COMMENT_NODE_NAME.getCode()));
                sHistoryComment.setCommentContent(sCommentConfigService.getValueByCode(CommentConfigEnum.SUPPLIER_EXTRANET_MODIFY_HISTORY_COMMENT_COMMENT_CONTENT.getCode()));
                sHistoryComment.setActionName(sCommentConfigService.getValueByCode(CommentConfigEnum.SUPPLIER_EXTRANET_MODIFY_HISTORY_COMMENT_ACTION_NAME.getCode()));
                sHistoryComment.setCommentType(HistoryCommentTypeEnum.INTRANET.getCode());//'类型（1：内网，2：外网，3：内外网共用）
                sHistoryComment.setSetupTime(new Date());
                sHistoryComment.setBaseFeilds(userId, null, 0, true);
                sHistoryCommentService.insert(sHistoryComment);
            }
            extSSuppliersMapper.updateBaseInfoById(sSuppliers);


            //合格供方修改时记录sSuppliers变化
            compare(sSuppliers, sSuppliersOld, sSuppliers.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);

            String intentionRegionalCompanyIds = suppliersDetailVo.getSuppliersVO().getIntentionRegionalCompanyIds();
            EntityWrapper sSupplierRcRelateWrapper = new EntityWrapper<>();
            SSupplierRcRelate sSupplierRcRelate = new SSupplierRcRelate();
            sSupplierRcRelate.setSuppliersId(sSuppliers.getId());
            sSupplierRcRelate.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            sSupplierRcRelateWrapper.setEntity(sSupplierRcRelate);
            List<SSupplierRcRelate> lsSSupplierRcRelateOld = sSupplierRcRelateService.selectList(sSupplierRcRelateWrapper);
            if (StringUtils.isNotEmpty(intentionRegionalCompanyIds)) {
                String[] intentionRegionalCompanyIdArr = intentionRegionalCompanyIds.split(",");
                List<SSupplierRcRelate> lsSSupplierRcRelateOldCopy = new ArrayList<>();
                lsSSupplierRcRelateOldCopy.addAll(lsSSupplierRcRelateOld);
                boolean isINspection = false;//是否需要资助审查
                if (lsSSupplierRcRelateOld == null || lsSSupplierRcRelateOld.size() == 0) isINspection = true;
                for (int i = lsSSupplierRcRelateOld.size() - 1; i >= 0; i--) {
                    SSupplierRcRelate objOld = lsSSupplierRcRelateOld.get(i);
                    if (objOld.getSupplierBigStatus() == SupplierBigStatusEnum.POTENTIAL.getCode()
                            && (objOld.getSupplierStatus() == Integer.valueOf(SupplierStatusEnum.QUALIFICATION_INSPECTION.getCode())
                            || objOld.getSupplierStatus() == Integer.valueOf(SupplierStatusEnum.PENDING_MODIFY.getCode()))) {//没有一个在资质审查步骤
                        isINspection = true;
                    }
                }
                for (String intentionRegionalCompanyId : intentionRegionalCompanyIdArr) {
                    boolean isNew = true;
                    for (int i = lsSSupplierRcRelateOld.size() - 1; i >= 0; i--) {
                        SSupplierRcRelate objOld = lsSSupplierRcRelateOld.get(i);
                        if (objOld.getRegionalCompanyId().equals(intentionRegionalCompanyId)) {
                            lsSSupplierRcRelateOldCopy.remove(objOld);
                            if (SupplierStatusEnum.PENDING_MODIFY.getCode().equals(objOld.getSupplierStatus() + "")) {
                                SSupplierRcRelate objOldCopy = new SSupplierRcRelate();
                                BeanUtils.copyProperties(objOld, objOldCopy);
                                compare(objOldCopy, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                                objOld.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.QUALIFICATION_INSPECTION.getCode()));
                                objOld.setUpdateBy(userId);
                                objOld.setUpdateDate(new Date());
                                sSupplierRcRelateService.updateById(objOld);
                            }
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew) {
                        SSupplierRcRelate obj = new SSupplierRcRelate();
                        obj.setId(IdGen.uuid());
                        obj.setSuppliersId(sSuppliers.getId());
                        obj.setRegionalCompanyId(intentionRegionalCompanyId);
                        obj.setSupplierCategoryIds(sSuppliers.getSupplierCategoryIds());
                        obj.setSupplierServiceCategoryIds(sSuppliers.getSupplierServiceCategoryIds());
                        obj.setSupplierSource(SupplierSourceEnum.ADD.getCode());
                        if (isINspection) {
                            obj.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.QUALIFICATION_INSPECTION.getCode()));
                        } else {
                            obj.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.SITE_INSPECTION.getCode()));
                        }
                        obj.setSupplierBigStatus(SupplierBigStatusEnum.POTENTIAL.getCode());
                        obj.setBaseFeilds(userId, null, 0, true);
                        sSupplierRcRelateService.insert(obj);
                        compare(obj, null, obj.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    }
                }
                for (SSupplierRcRelate oldCopy : lsSSupplierRcRelateOldCopy) {
                    if (oldCopy.getSupplierBigStatus() == SupplierBigStatusEnum.POTENTIAL.getCode() && oldCopy.getSupplierSource() != SupplierSourceEnum.INCURSION.getCode()) {//只有潜在的非引入可以删除
                        compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                        oldCopy.setUpdateBy(userId);
                        oldCopy.setUpdateDate(new Date());
                        oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                        sSupplierRcRelateService.updateById(oldCopy);
                    }
                }
            } else {//全部删除
                for (SSupplierRcRelate obj : lsSSupplierRcRelateOld) {
                    if (obj.getSupplierBigStatus() == SupplierBigStatusEnum.POTENTIAL.getCode() && obj.getSupplierSource() != SupplierSourceEnum.INCURSION.getCode()) {//只有潜在的非引入可以删除
                        compare(null, obj, obj.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                        obj.setUpdateBy(userId);
                        obj.setUpdateDate(new Date());
                        obj.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                        sSupplierRcRelateService.updateById(obj);
                    }
                }
            }

            //供方基本情况-供方分类关系表保存
            String supplierCategoryIds = suppliersDetailVo.getSuppliersVO().getSupplierCategoryIds();
            EntityWrapper sSupplierCategoryRelateWrapper = new EntityWrapper<>();
            SSupplierCategoryRelate sSupplierCategoryRelate = new SSupplierCategoryRelate();
            sSupplierCategoryRelate.setSuppliersId(sSuppliers.getId());
            sSupplierCategoryRelate.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            sSupplierCategoryRelateWrapper.setEntity(sSupplierCategoryRelate);
            sSupplierCategoryRelateService.delete(sSupplierCategoryRelateWrapper);
            if (StringUtils.isNotEmpty(supplierCategoryIds)) {
                String[] supplierCategoryIdArr = supplierCategoryIds.split(",");
                List<SSupplierCategoryRelate> sSupplierCategoryRelateLs = new ArrayList<>();
                for (String supplierCategoryId : supplierCategoryIdArr) {
                    SSupplierCategoryRelate obj = new SSupplierCategoryRelate();
                    obj.setId(IdGen.uuid());
                    obj.setSuppliersId(sSuppliers.getId());
                    obj.setCategoryId(supplierCategoryId);
                    obj.setBaseFeilds(userId, null, 0, true);
                    sSupplierCategoryRelateLs.add(obj);
                }
                if (sSupplierCategoryRelateLs != null && sSupplierCategoryRelateLs.size() > 0)
                    sSupplierCategoryRelateService.insertBatch(sSupplierCategoryRelateLs);
            }

            //保存or更新供方信息-资质等级
            EntityWrapper sSupplierQualificationGradeWrapper = new EntityWrapper<>();
            SSupplierQualificationGrade sSupplierQualificationGrade = new SSupplierQualificationGrade();
            sSupplierQualificationGrade.setSuppliersId(sSuppliers.getId());
            sSupplierQualificationGrade.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            sSupplierQualificationGradeWrapper.setEntity(sSupplierQualificationGrade);
            List<SSupplierQualificationGrade> lsSSupplierQualificationGradeOld = sSupplierQualificationGradeService.selectList(sSupplierQualificationGradeWrapper);
            if (suppliersDetailVo.getLstSuppliersQualificationGradeVO() != null &&
                    suppliersDetailVo.getLstSuppliersQualificationGradeVO().size() != 0) {
                List<SSupplierQualificationGrade> lsSSupplierQualificationGrade = ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersQualificationGradeVO(), SSupplierQualificationGrade.class);
                //合格供方修改时记录sSuppliers变化
                List<SSupplierQualificationGrade> lsSSupplierQualificationGradeOldCopy = new ArrayList<>();
                lsSSupplierQualificationGradeOldCopy.addAll(lsSSupplierQualificationGradeOld);
                for (SSupplierQualificationGrade objNew : lsSSupplierQualificationGrade) {
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(userId, null, 0, true);
                    } else {
                        objNew.setBaseFeilds(userId, null, 0, false);
                    }
                    objNew.setSuppliersId(sSuppliers.getId());
                    boolean isNew = true;
                    for (int i = lsSSupplierQualificationGradeOld.size() - 1; i >= 0; i--) {
                        SSupplierQualificationGrade objOld = lsSSupplierQualificationGradeOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSSupplierQualificationGradeOldCopy.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SSupplierQualificationGrade oldCopy : lsSSupplierQualificationGradeOldCopy) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierQualificationGradeService.updateById(oldCopy);
                }
                sSupplierQualificationGradeService.insertOrUpdateAllColumnBatch(lsSSupplierQualificationGrade);
            } else {//全部删除
                for (SSupplierQualificationGrade oldSSupplierQualificationGrade : lsSSupplierQualificationGradeOld) {
                    compare(null, oldSSupplierQualificationGrade, oldSSupplierQualificationGrade.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldSSupplierQualificationGrade.setUpdateBy(userId);
                    oldSSupplierQualificationGrade.setUpdateDate(new Date());
                    oldSSupplierQualificationGrade.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierQualificationGradeService.updateById(oldSSupplierQualificationGrade);
                }
            }

            //保存or更新供方基本情况-股东
            EntityWrapper wrapperSSupplierStockholder = new EntityWrapper<>();
            SSupplierStockholder sSupplierStockholder = new SSupplierStockholder();
            sSupplierStockholder.setSuppliersId(sSuppliers.getId());
            sSupplierStockholder.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierStockholder.setEntity(sSupplierStockholder);
            List<SSupplierStockholder> lsSSupplierStockholderOld = sSupplierStockholderService.selectList(wrapperSSupplierStockholder);
            if (suppliersDetailVo.getLstSuppliersStockHolderVO() != null &&
                    suppliersDetailVo.getLstSuppliersStockHolderVO().size() != 0) {
                List<SSupplierStockholder> lsSSupplierStockholder = ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersStockHolderVO(), SSupplierStockholder.class);
                //比较
                List<SSupplierStockholder> lsSSupplierStockholderOldCopy = new ArrayList<>();
                lsSSupplierStockholderOldCopy.addAll(lsSSupplierStockholderOld);
                for (SSupplierStockholder objNew : lsSSupplierStockholder) {
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(userId, null, 0, true);
                    } else {
                        objNew.setBaseFeilds(userId, null, 0, false);
                    }
                    objNew.setSuppliersId(sSuppliers.getId());
                    boolean isNew = true;
                    for (int i = lsSSupplierStockholderOld.size() - 1; i >= 0; i--) {
                        SSupplierStockholder objOld = lsSSupplierStockholderOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSSupplierStockholderOldCopy.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SSupplierStockholder oldCopy : lsSSupplierStockholderOldCopy) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierStockholderService.updateById(oldCopy);
                }
                sSupplierStockholderService.insertOrUpdateAllColumnBatch(lsSSupplierStockholder);
            } else {
                for (SSupplierStockholder oldCopy : lsSSupplierStockholderOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierStockholderService.updateById(oldCopy);
                }
            }

            //保存or更新供方基本情况-联系方式
            EntityWrapper wrapperSSupplierContactInfo = new EntityWrapper<>();
            SSupplierContactInfo sSupplierContactInfo = new SSupplierContactInfo();
            sSupplierContactInfo.setSuppliersId(sSuppliers.getId());
            sSupplierContactInfo.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierContactInfo.setEntity(sSupplierContactInfo);
            List<SSupplierContactInfo> lsSSupplierContactInfoOld = sSupplierContactInfoService.selectList(wrapperSSupplierContactInfo);
            if (suppliersDetailVo.getLstSuppliersContactInfoVO() != null &&
                    suppliersDetailVo.getLstSuppliersContactInfoVO().size() != 0) {
                List<SSupplierContactInfo> lsSSupplierContactInfo = ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersContactInfoVO(), SSupplierContactInfo.class);
                //比较
                List<SSupplierContactInfo> lsSSupplierContactInfoOldCopy = new ArrayList<>();
                lsSSupplierContactInfoOldCopy.addAll(lsSSupplierContactInfoOld);
                for (SSupplierContactInfo objNew : lsSSupplierContactInfo) {
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(userId, null, 0, true);
                    } else {
                        objNew.setBaseFeilds(userId, null, 0, false);
                    }
                    objNew.setSuppliersId(sSuppliers.getId());
                    boolean isNew = true;
                    for (int i = lsSSupplierContactInfoOld.size() - 1; i >= 0; i--) {
                        SSupplierContactInfo objOld = lsSSupplierContactInfoOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSSupplierContactInfoOldCopy.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SSupplierContactInfo oldCopy : lsSSupplierContactInfoOldCopy) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierContactInfoService.updateById(oldCopy);
                }
                sSupplierContactInfoService.insertOrUpdateAllColumnBatch(lsSSupplierContactInfo);
            } else {
                for (SSupplierContactInfo oldCopy : lsSSupplierContactInfoOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierContactInfoService.updateById(oldCopy);
                }
            }

            //保存or更新供方基本情况--获取信息类型
            EntityWrapper wrapperSSupplierObtainInformation = new EntityWrapper<>();
            SSupplierObtainInformation entrySSupplierObtainInformation = new SSupplierObtainInformation();
            entrySSupplierObtainInformation.setSuppliersId(sSuppliers.getId());
            entrySSupplierObtainInformation.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierObtainInformation.setEntity(entrySSupplierObtainInformation);
            SSupplierObtainInformation sSupplierObtainInformationOld = sSupplierObtainInformationService.selectOne(wrapperSSupplierObtainInformation);
            if (suppliersDetailVo.getSuppliersObtainInformationVO() != null) {
                SSupplierObtainInformation sSupplierObtainInformation = new SSupplierObtainInformation();
                BeanUtils.copyProperties(suppliersDetailVo.getSuppliersObtainInformationVO(), sSupplierObtainInformation);
                sSupplierObtainInformation.setSuppliersId(sSuppliers.getId());
                if (StringUtils.isEmpty(sSupplierObtainInformation.getId())) {
                    sSupplierObtainInformation.setId(IdGen.uuid());
                    sSupplierObtainInformation.setBaseFeilds(userId, null, 0, true);
                } else {
                    sSupplierObtainInformation.setBaseFeilds(userId, null, 0, false);
                }
                //比较
                compare(sSupplierObtainInformation, sSupplierObtainInformationOld, sSupplierObtainInformation.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                sSupplierObtainInformationService.insertOrUpdate(sSupplierObtainInformation);
            } else {
                if (sSupplierObtainInformationOld != null) {
                    compare(null, sSupplierObtainInformationOld, sSupplierObtainInformationOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    sSupplierObtainInformationOld.setUpdateBy(userId);
                    sSupplierObtainInformationOld.setUpdateDate(new Date());
                    sSupplierObtainInformationOld.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierObtainInformationService.updateById(sSupplierObtainInformationOld);
                }
            }

            //保存or更新供方基本情况--关联母公司信息
            EntityWrapper wrapperSSupplierRelateParentCmpy = new EntityWrapper<>();
            SSupplierRelateParentCmpy entrySSupplierRelateParentCmpy = new SSupplierRelateParentCmpy();
            entrySSupplierRelateParentCmpy.setSuppliersId(sSuppliers.getId());
            entrySSupplierRelateParentCmpy.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierRelateParentCmpy.setEntity(entrySSupplierRelateParentCmpy);
            List<SSupplierRelateParentCmpy> sSupplierRelateParentCmpyOldls = sSupplierRelateParentCmpyService.selectList(wrapperSSupplierRelateParentCmpy);
//            if(sSupplierRelateParentCmpyOldls!=null&&sSupplierRelateParentCmpyOldls.size()>1){
//                throw new RuntimeException("母公司数据异常");
//            }
            SSupplierRelateParentCmpy sSupplierRelateParentCmpyOld = new SSupplierRelateParentCmpy();
            if (sSupplierRelateParentCmpyOldls != null && sSupplierRelateParentCmpyOldls.size() == 1)
                sSupplierRelateParentCmpyOld = sSupplierRelateParentCmpyOldls.get(0);
            if (suppliersDetailVo.getSuppliersRelateParentCmpyVO() != null) {
                SSupplierRelateParentCmpy sSupplierRelateParentCmpy = new SSupplierRelateParentCmpy();
                if (suppliersDetailVo.getSuppliersRelateParentCmpyVO().getHasRelateParentCompany() != null &&
                        suppliersDetailVo.getSuppliersRelateParentCmpyVO().getHasRelateParentCompany() == CommonConstants.YES_INTEGER) {
                    BeanUtils.copyProperties(suppliersDetailVo.getSuppliersRelateParentCmpyVO(), sSupplierRelateParentCmpy);
                } else {
                    sSupplierRelateParentCmpy.setHasRelateParentCompany(CommonConstants.NO_INTEGER);
                    sSupplierRelateParentCmpy.setCreditLicenseCodeFlag(suppliersDetailVo.getSuppliersRelateParentCmpyVO().getCreditLicenseCodeFlag());
                }
                sSupplierRelateParentCmpy.setSuppliersId(sSuppliers.getId());
                if (StringUtils.isEmpty(sSupplierRelateParentCmpyOld.getId())) {
                    sSupplierRelateParentCmpy.setBaseFeilds(userId, null, 0, true);
                } else {
                    sSupplierRelateParentCmpy.setBaseFeilds(userId, null, 0, false);
                    sSupplierRelateParentCmpy.setId(sSupplierRelateParentCmpyOld.getId());
                }
                //比较
                compare(sSupplierRelateParentCmpy, sSupplierRelateParentCmpyOld, sSupplierRelateParentCmpy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                sSupplierRelateParentCmpyService.insertOrUpdate(sSupplierRelateParentCmpy);
            }

            //保存or更新供方基本情况--业务状况
            EntityWrapper wrapperSSupplierBusinessSituation = new EntityWrapper<>();
            SSupplierBusinessSituation entrySSupplierBusinessSituation = new SSupplierBusinessSituation();
            entrySSupplierBusinessSituation.setSuppliersId(sSuppliers.getId());
            entrySSupplierBusinessSituation.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierBusinessSituation.setEntity(entrySSupplierBusinessSituation);
            SSupplierBusinessSituation sSupplierBusinessSituationold = sSupplierBusinessSituationService.selectOne(wrapperSSupplierBusinessSituation);
            if (suppliersDetailVo.getSuppliersBusinessSituationVO() != null) {
                SSupplierBusinessSituation sSupplierBusinessSituation = new SSupplierBusinessSituation();
                BeanUtils.copyProperties(suppliersDetailVo.getSuppliersBusinessSituationVO(), sSupplierBusinessSituation);
                sSupplierBusinessSituation.setSuppliersId(sSuppliers.getId());
                if (StringUtils.isEmpty(sSupplierBusinessSituation.getId())) {
                    sSupplierBusinessSituation.setId(IdGen.uuid());
                    sSupplierBusinessSituation.setBaseFeilds(userId, null, 0, true);
                } else {
                    sSupplierBusinessSituation.setBaseFeilds(userId, null, 0, false);
                }
                //比较
                compare(sSupplierBusinessSituation, sSupplierBusinessSituationold, sSupplierBusinessSituation.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                sSupplierBusinessSituationService.insertOrUpdateAllColumn(sSupplierBusinessSituation);
            } else {
                if (sSupplierBusinessSituationold != null) {
                    compare(null, sSupplierBusinessSituationold, sSupplierBusinessSituationold.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    sSupplierBusinessSituationold.setUpdateBy(userId);
                    sSupplierBusinessSituationold.setUpdateDate(new Date());
                    sSupplierBusinessSituationold.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierBusinessSituationService.updateById(sSupplierBusinessSituationold);
                }
            }

            //保存or更新供方近三年业绩-战略合作+一般合作
            EntityWrapper wrapperSSuppliersLastThreeAchieve = new EntityWrapper<>();
            SSuppliersLastThreeAchieve sSuppliersLastThreeAchieve = new SSuppliersLastThreeAchieve();
            sSuppliersLastThreeAchieve.setSuppliersId(sSuppliers.getId());
            sSuppliersLastThreeAchieve.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            sSuppliersLastThreeAchieve.setSourceType(CommonConstants.EXTERNAL);
            wrapperSSuppliersLastThreeAchieve.setEntity(sSuppliersLastThreeAchieve);
            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveOld = sSuppliersLastThreeAchieveService.selectList(wrapperSSuppliersLastThreeAchieve);
            List<SuppliersLastThreeMajorAchievenVO> lstSuppliersLastThreeMajorAchievenVO = suppliersDetailVo.getLstSuppliersLastThreeMajorAchievenVO();
            List<SuppliersLastThreeCommonAchievenVO> lstSuppliersLastThreeCommonAchievenVO = suppliersDetailVo.getLstSuppliersLastThreeCommonAchievenVO();
            if (lsSSuppliersLastThreeAchieveOld == null) lsSSuppliersLastThreeAchieveOld = new ArrayList<>();
            if (lstSuppliersLastThreeMajorAchievenVO == null) lstSuppliersLastThreeMajorAchievenVO = new ArrayList<>();
            if (lstSuppliersLastThreeCommonAchievenVO == null)
                lstSuppliersLastThreeCommonAchievenVO = new ArrayList<>();
            Map<Integer, List<AttachmentVO>> attachmentVOmap = suppliersDetailVo.getMapAttachmentVOs();
            if (attachmentVOmap == null) attachmentVOmap = new HashMap<Integer, List<AttachmentVO>>();
            List<AttachmentVO> lstAttachment = new ArrayList<>();

            for (int i = lstSuppliersLastThreeMajorAchievenVO.size() - 1; i >= 0; i--) {
                SuppliersLastThreeMajorAchievenVO obj = lstSuppliersLastThreeMajorAchievenVO.get(i);
                if (StringUtils.isEmpty(obj.getCooperativeUnitName())) {
                    lstSuppliersLastThreeMajorAchievenVO.remove(obj);
                }
                obj.setCooperativeType(CommonConstants.MAJOR_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
                String uuid = IdGen.uuid();
                if (StringUtils.isEmpty(obj.getId())) {
                    obj.setId(uuid);
                }
                List<AttachmentVO> lsAttachment = obj.getLstattachmentVO();
                if (lsAttachment != null && lsAttachment.size() > 0) {
                    for (AttachmentVO attachmentVO : lsAttachment) {
                        attachmentVO.setFormId(sSuppliers.getId());
                        attachmentVO.setRelatedId(obj.getId());
                        attachmentVO.setAttachmentType(1);
                    }
                    lstAttachment.addAll(lsAttachment);
                }
            }
            for (int i = lstSuppliersLastThreeCommonAchievenVO.size() - 1; i >= 0; i--) {
                SuppliersLastThreeCommonAchievenVO obj = lstSuppliersLastThreeCommonAchievenVO.get(i);
                if (StringUtils.isEmpty(obj.getCooperativeUnitName())) {
                    lstSuppliersLastThreeCommonAchievenVO.remove(obj);
                }
                obj.setCooperativeType(CommonConstants.COMMON_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
                String uuid = IdGen.uuid();
                if (StringUtils.isEmpty(obj.getId())) {
                    obj.setId(uuid);
                }
                List<AttachmentVO> lsAttachmentVO = obj.getLstattachmentVO();
                if (lsAttachmentVO != null && lsAttachmentVO.size() > 0) {
                    for (AttachmentVO attachmentVO : lsAttachmentVO) {
                        attachmentVO.setFormId(sSuppliers.getId());
                        attachmentVO.setRelatedId(obj.getId());
                        attachmentVO.setAttachmentType(1);
                    }
                    lstAttachment.addAll(lsAttachmentVO);
                }
            }
            if (lstAttachment != null && lstAttachment.size() > 0)
                attachmentVOmap.put(1, lstAttachment);//添加1：供方三年业绩合同附件
            suppliersDetailVo.setMapAttachmentVOs(attachmentVOmap);

            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieve = new ArrayList<>();
            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveMajor = ListObjCopyUtil.copyTo(lstSuppliersLastThreeMajorAchievenVO, SSuppliersLastThreeAchieve.class);
            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveCommon = ListObjCopyUtil.copyTo(lstSuppliersLastThreeCommonAchievenVO, SSuppliersLastThreeAchieve.class);
            lsSSuppliersLastThreeAchieve.addAll(lsSSuppliersLastThreeAchieveMajor);
            lsSSuppliersLastThreeAchieve.addAll(lsSSuppliersLastThreeAchieveCommon);
            if (lsSSuppliersLastThreeAchieve != null &&
                    lsSSuppliersLastThreeAchieve.size() != 0) {
                //比较
                List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveOldCopy = new ArrayList<>();
                lsSSuppliersLastThreeAchieveOldCopy.addAll(lsSSuppliersLastThreeAchieveOld);
                for (SSuppliersLastThreeAchieve objNew : lsSSuppliersLastThreeAchieve) {
                    objNew.setSuppliersId(sSuppliers.getId());
                    objNew.setSourceType(CommonConstants.EXTERNAL);
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(userId, null, 0, true);
                    } else {
                        objNew.setBaseFeilds(userId, null, 0, false);
                    }
                    boolean isNew = true;
                    for (int i = lsSSuppliersLastThreeAchieveOld.size() - 1; i >= 0; i--) {
                        SSuppliersLastThreeAchieve objOld = lsSSuppliersLastThreeAchieveOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSSuppliersLastThreeAchieveOldCopy.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SSuppliersLastThreeAchieve oldCopy : lsSSuppliersLastThreeAchieveOldCopy) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSuppliersLastThreeAchieveService.updateById(oldCopy);
                }
                sSuppliersLastThreeAchieveService.insertOrUpdateAllColumnBatch(lsSSuppliersLastThreeAchieve);
            } else {
                for (SSuppliersLastThreeAchieve oldCopy : lsSSuppliersLastThreeAchieveOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSuppliersLastThreeAchieveService.updateById(oldCopy);
                }
            }

            //保存or更新附件
//            EntityWrapper sAttachmentWrapper = new EntityWrapper<>();
//            SAttachment sAttachmentEntry = new SAttachment();
//            sAttachmentEntry.setFormId(sSuppliers.getId());
//            sAttachmentEntry.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
//            sAttachmentWrapper.setEntity(sAttachmentEntry);
//            List<SAttachment> lsSAttachmentOld = sAttachmentService.selectList(sAttachmentWrapper);

            Map<String, Object> mapParams = new HashMap<String, Object>();
            mapParams.put("formId", sSuppliers.getId());
            mapParams.put("lstNotInType", new Integer[]{AttachmentTypeEnum.ATTACHMENT_TYPE_13.getCode(), AttachmentTypeEnum.ATTACHMENT_TYPE_14.getCode()});
            List<ExtSAttachment> lsSAttachmentOld = sAttachmentService.getSAttachmentByCnd(mapParams);
            if (suppliersDetailVo.getMapAttachmentVOs() != null &&
                    suppliersDetailVo.getMapAttachmentVOs().size() != 0) {
                Map<Integer, List<AttachmentVO>> map = suppliersDetailVo.getMapAttachmentVOs();

                List<SAttachment> lsSAttachmentOldCopy = new ArrayList<>();
                lsSAttachmentOldCopy.addAll(lsSAttachmentOld);
                List<SAttachment> lsSAttachment = new ArrayList<>();
                for (List<AttachmentVO> lsAttachmentVO : map.values()) {
                    lsSAttachment.addAll(ListObjCopyUtil.copyTo(lsAttachmentVO, SAttachment.class));
                }
                //比较
                for (SAttachment objNew : lsSAttachment) {
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(userId, null, 0, true);
                    } else {
                        objNew.setBaseFeilds(userId, null, 0, false);
                    }
                    objNew.setFormId(sSuppliers.getId());
//					objNew.setRelatedId(sSuppliers.getId());
                    boolean isNew = true;
                    for (int i = lsSAttachmentOld.size() - 1; i >= 0; i--) {
                        SAttachment objOld = lsSAttachmentOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSAttachmentOld.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SAttachment oldCopy : lsSAttachmentOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sAttachmentService.updateById(oldCopy);
                }
                if (lsSAttachment != null && lsSAttachment.size() > 0)
                    sAttachmentService.insertOrUpdateAllColumnBatch(lsSAttachment);
            } else {
                for (SAttachment oldCopy : lsSAttachmentOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sAttachmentService.updateById(oldCopy);
                }
            }


            //保存or更新供方基本情况--银行账号
            String supplierId = sSuppliers.getId();
            EntityWrapper wrapperSSupplierBankAccount = new EntityWrapper<>();
            SSupplierBankAccount entrySSupplierBankAccount = new SSupplierBankAccount();
            entrySSupplierBankAccount.setSuppliersId(sSuppliers.getId());
            entrySSupplierBankAccount.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierBankAccount.setEntity(entrySSupplierBankAccount);
            List<SSupplierBankAccount> oldLstBankAccount = sSupplierBankAccountService.selectList(wrapperSSupplierBankAccount);
            Map<String, SSupplierBankAccount> oldBankAccountMap = oldLstBankAccount.stream().collect(Collectors.toMap(SSupplierBankAccount::getId, p -> p));
            List<SuppliersBankAccountVO> lstBankAccountVO = suppliersDetailVo.getLstSuppliersBankAccountVO();
            List<String> bankAccountIds = lstBankAccountVO.stream().map(SuppliersBankAccountVO::getId).collect(Collectors.toList());
            if (lstBankAccountVO != null && lstBankAccountVO.size() > 0) {
                lstBankAccountVO.forEach(item -> {
                    SSupplierBankAccount bankAccountVo = new SSupplierBankAccount();
                    bankAccountVo.setSuppliersId(supplierId);
                    bankAccountVo.setAccountNumber(item.getAccountNumber());
                    bankAccountVo.setAccountType(item.getAccountType());
                    bankAccountVo.setBankName(item.getBankName());
                    bankAccountVo.setBankNumber(item.getBankNumber());
                    bankAccountVo.setId(item.getId());
                    bankAccountVo.setBaseFeilds(UserUtils.getCurrentUserId(), "", CommonConstants.DEL_FLAG_NORMAL, StringUtils.isEmpty(item.getId()));
                    sSupplierBankAccountService.insertOrUpdate(bankAccountVo);

                    try {
                        compare(bankAccountVo, oldBankAccountMap.get(item.getId()), bankAccountVo.getId(), supplierId, sSupplierRcRelateStatus, userId);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                });
            }

            if (oldLstBankAccount != null && oldLstBankAccount.size() > 0) {
                //数据库存在，但提交的数据不存在了，则进行逻辑删除操作
                List<SSupplierBankAccount> delList = oldLstBankAccount.stream().filter(item -> !bankAccountIds.contains(item.getId())).collect(Collectors.toList());
                delList.forEach(item -> {
                    item.setBaseFeilds(UserUtils.getCurrentUserId(), "", CommonConstants.DEL_FLAG_DELETE, false);
                    sSupplierBankAccountService.updateById(item);
                    try {
                        compare(null, item, item.getId(), supplierId, sSupplierRcRelateStatus, userId);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                });

            }

            hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS, "保存成功");
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("系统错误");
        }
        return hResult;
    }

    /***
     * 内网供方更新
     * @param suppliersDetailVo
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackForClassName = {"RuntimeException", "Exception"})
    public RestReturnResult<Object> innerUpdateSuppliers(SuppliersDetailVO suppliersDetailVo) {
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, suppliersDetailVo, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

        try {
            if (StringUtils.isEmpty(suppliersDetailVo.getSuppliersVO().getId())) {
                throw new RuntimeException("id不能为空");
            }
            SSuppliers sSuppliersOld = super.selectById(suppliersDetailVo.getSuppliersVO().getId());
            if (sSuppliersOld.getModifiedFlag() != null && sSuppliersOld.getModifiedFlag() == CommonConstants.YES_INTEGER) {
                throw new RuntimeException("供方在修改审批中，请联系服务地区公司管理员进行审核");
            }
            SSuppliers sSuppliers = new SSuppliers();
            if (suppliersDetailVo.getSuppliersVO().getCreditLicenseCodeFlag() == 1) {//信用代码或营业执照号（1：统一社会信用代码， 2：营业执照号）
                sSuppliers.setSocialCreditCode(suppliersDetailVo.getSuppliersVO().getSocialCreditCode());
            } else {
                sSuppliers.setBusinessLicenseNumber(suppliersDetailVo.getSuppliersVO().getBusinessLicenseNumber());
            }
            sSuppliers.setId(suppliersDetailVo.getSuppliersVO().getId());
            Integer count = extSSuppliersMapper.findSupplierCount(sSuppliers);
            if (count != null && count > 0) {
                throw new RuntimeException("营业执照号/统一社会信用代码 已存在");
            }
            //保存or更新供方基本情况
            BeanUtils.copyProperties(suppliersDetailVo.getSuppliersVO(), sSuppliers);

            String userId = UserUtils.getCurrentUserId();
            sSuppliers.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
            extSSuppliersMapper.updateBaseInfoById(sSuppliers);

            String rcRelatedId = suppliersDetailVo.getSuppliersVO().getRcRelatedId();//子表id
            SSupplierRcRelate sSupplierRcRelateStatus = new SSupplierRcRelate();
            if (StringUtils.isNotEmpty(rcRelatedId)) {
                sSupplierRcRelateStatus = sSupplierRcRelateService.selectById(rcRelatedId);

                //意向地区公司合格分类修改
                sSupplierRcRelateStatus.setSupplierCategoryActualIds(suppliersDetailVo.getSuppliersVO().getQualifiedCategoryIds());
                sSupplierRcRelateStatus.setBaseFeilds(UserUtils.getCurrentUserId(), null, CommonConstants.NO_INTEGER, false);
                sSupplierRcRelateStatus.setSupplierCategoryIds(sSuppliers.getSupplierCategoryIds());
                sSupplierRcRelateStatus.setSupplierServiceCategoryIds(sSuppliers.getSupplierServiceCategoryIds());
                sSupplierRcRelateService.updateAllColumnById(sSupplierRcRelateStatus);
            }
            //合格供方修改时记录sSuppliers变化
            compare(sSuppliers, sSuppliersOld, sSuppliers.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);

            //保存or更新意向公司关系表保存
            String intentionRegionalCompanyIds = suppliersDetailVo.getSuppliersVO().getIntentionRegionalCompanyIds();
            EntityWrapper sSupplierRcRelateWrapper = new EntityWrapper<>();
            SSupplierRcRelate sSupplierRcRelate = new SSupplierRcRelate();
            sSupplierRcRelate.setSuppliersId(sSuppliers.getId());
            sSupplierRcRelate.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            sSupplierRcRelateWrapper.setEntity(sSupplierRcRelate);
            List<SSupplierRcRelate> lsSSupplierRcRelateOld = sSupplierRcRelateService.selectList(sSupplierRcRelateWrapper);
            if (StringUtils.isNotEmpty(intentionRegionalCompanyIds)) {
                String[] intentionRegionalCompanyIdArr = intentionRegionalCompanyIds.split(",");
                List<SSupplierRcRelate> lsSSupplierRcRelateOldCopy = new ArrayList<>();
                lsSSupplierRcRelateOldCopy.addAll(lsSSupplierRcRelateOld);
                boolean isINspection = false;//是否需要资助审查
                if (lsSSupplierRcRelateOld == null || lsSSupplierRcRelateOld.size() == 0) isINspection = true;
                for (int i = lsSSupplierRcRelateOld.size() - 1; i >= 0; i--) {
                    SSupplierRcRelate objOld = lsSSupplierRcRelateOld.get(i);
                    if (objOld.getSupplierBigStatus() == SupplierBigStatusEnum.POTENTIAL.getCode()
                            && (objOld.getSupplierStatus() == Integer.valueOf(SupplierStatusEnum.QUALIFICATION_INSPECTION.getCode())
                            || objOld.getSupplierStatus() == Integer.valueOf(SupplierStatusEnum.PENDING_MODIFY.getCode()))) {
                        isINspection = true;
                    }
                }
                for (String intentionRegionalCompanyId : intentionRegionalCompanyIdArr) {
                    SSupplierRcRelate obj = new SSupplierRcRelate();
                    obj.setId(IdGen.uuid());
                    obj.setSuppliersId(sSuppliers.getId());
                    obj.setRegionalCompanyId(intentionRegionalCompanyId);
                    obj.setSupplierCategoryIds(sSuppliers.getSupplierCategoryIds());
                    obj.setSupplierServiceCategoryIds(sSuppliers.getSupplierServiceCategoryIds());
                    obj.setSupplierSource(SupplierSourceEnum.ADD.getCode());
                    if (isINspection) {
                        obj.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.QUALIFICATION_INSPECTION.getCode()));
                    } else {
                        obj.setSupplierStatus(Integer.valueOf(SupplierStatusEnum.SITE_INSPECTION.getCode()));
                    }
                    obj.setSupplierBigStatus(SupplierBigStatusEnum.POTENTIAL.getCode());
                    obj.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                    boolean isNew = true;
                    for (int i = lsSSupplierRcRelateOld.size() - 1; i >= 0; i--) {
                        SSupplierRcRelate objOld = lsSSupplierRcRelateOld.get(i);
                        if (objOld.getRegionalCompanyId().equals(intentionRegionalCompanyId)) {
                            lsSSupplierRcRelateOldCopy.remove(objOld);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew) {
                        sSupplierRcRelateService.insert(obj);
                        compare(obj, null, obj.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    }
                }
                for (SSupplierRcRelate oldCopy : lsSSupplierRcRelateOldCopy) {
                    if (oldCopy.getSupplierBigStatus() == SupplierBigStatusEnum.POTENTIAL.getCode() && oldCopy.getSupplierSource() != SupplierSourceEnum.INCURSION.getCode()) {
                        compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                        oldCopy.setUpdateBy(userId);
                        oldCopy.setUpdateDate(new Date());
                        oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                        sSupplierRcRelateService.updateById(oldCopy);
                    }
                }
            } else {//全部删除
                for (SSupplierRcRelate obj : lsSSupplierRcRelateOld) {
                    if (obj.getSupplierBigStatus() == SupplierBigStatusEnum.POTENTIAL.getCode() && obj.getSupplierSource() != SupplierSourceEnum.INCURSION.getCode()) {
                        compare(null, obj, obj.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                        obj.setUpdateBy(userId);
                        obj.setUpdateDate(new Date());
                        obj.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                        sSupplierRcRelateService.updateById(obj);
                    }
                }
            }

            //供方基本情况-供方分类关系表保存
            String supplierCategoryIds = suppliersDetailVo.getSuppliersVO().getSupplierCategoryIds();
            EntityWrapper sSupplierCategoryRelateWrapper = new EntityWrapper<>();
            SSupplierCategoryRelate sSupplierCategoryRelate = new SSupplierCategoryRelate();
            sSupplierCategoryRelate.setSuppliersId(sSuppliers.getId());
            sSupplierCategoryRelate.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            sSupplierCategoryRelateWrapper.setEntity(sSupplierCategoryRelate);
            sSupplierCategoryRelateService.delete(sSupplierCategoryRelateWrapper);
            if (StringUtils.isNotEmpty(supplierCategoryIds)) {
                String[] supplierCategoryIdArr = supplierCategoryIds.split(",");
                List<SSupplierCategoryRelate> sSupplierCategoryRelateLs = new ArrayList<>();
                for (String supplierCategoryId : supplierCategoryIdArr) {
                    SSupplierCategoryRelate obj = new SSupplierCategoryRelate();
                    obj.setId(IdGen.uuid());
                    obj.setSuppliersId(sSuppliers.getId());
                    obj.setCategoryId(supplierCategoryId);
                    obj.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                    sSupplierCategoryRelateLs.add(obj);
                }
                if (sSupplierCategoryRelateLs != null && sSupplierCategoryRelateLs.size() > 0)
                    sSupplierCategoryRelateService.insertBatch(sSupplierCategoryRelateLs);
            }

            //保存or更新供方信息-资质等级
            EntityWrapper sSupplierQualificationGradeWrapper = new EntityWrapper<>();
            SSupplierQualificationGrade sSupplierQualificationGrade = new SSupplierQualificationGrade();
            sSupplierQualificationGrade.setSuppliersId(sSuppliers.getId());
            sSupplierQualificationGrade.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            sSupplierQualificationGradeWrapper.setEntity(sSupplierQualificationGrade);
            List<SSupplierQualificationGrade> lsSSupplierQualificationGradeOld = sSupplierQualificationGradeService.selectList(sSupplierQualificationGradeWrapper);
            if (suppliersDetailVo.getLstSuppliersQualificationGradeVO() != null &&
                    suppliersDetailVo.getLstSuppliersQualificationGradeVO().size() != 0) {
                List<SSupplierQualificationGrade> lsSSupplierQualificationGrade = ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersQualificationGradeVO(), SSupplierQualificationGrade.class);
                //合格供方修改时记录sSuppliers变化
                List<SSupplierQualificationGrade> lsSSupplierQualificationGradeOldCopy = new ArrayList<>();
                lsSSupplierQualificationGradeOldCopy.addAll(lsSSupplierQualificationGradeOld);
                for (SSupplierQualificationGrade objNew : lsSSupplierQualificationGrade) {
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                    } else {
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
                    }
                    objNew.setSuppliersId(sSuppliers.getId());
                    boolean isNew = true;
                    for (int i = lsSSupplierQualificationGradeOld.size() - 1; i >= 0; i--) {
                        SSupplierQualificationGrade objOld = lsSSupplierQualificationGradeOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSSupplierQualificationGradeOldCopy.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SSupplierQualificationGrade oldCopy : lsSSupplierQualificationGradeOldCopy) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setUpdateBy(userId);
                    sSupplierQualificationGradeService.updateById(oldCopy);
                }
                sSupplierQualificationGradeService.insertOrUpdateAllColumnBatch(lsSSupplierQualificationGrade);
            } else {//全部删除
                for (SSupplierQualificationGrade oldSSupplierQualificationGrade : lsSSupplierQualificationGradeOld) {
                    compare(null, oldSSupplierQualificationGrade, oldSSupplierQualificationGrade.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldSSupplierQualificationGrade.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    oldSSupplierQualificationGrade.setUpdateDate(new Date());
                    oldSSupplierQualificationGrade.setUpdateBy(userId);
                    sSupplierQualificationGradeService.updateById(oldSSupplierQualificationGrade);
                }
            }

            //保存or更新供方基本情况-股东
            EntityWrapper wrapperSSupplierStockholder = new EntityWrapper<>();
            SSupplierStockholder sSupplierStockholder = new SSupplierStockholder();
            sSupplierStockholder.setSuppliersId(sSuppliers.getId());
            sSupplierStockholder.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierStockholder.setEntity(sSupplierStockholder);
            List<SSupplierStockholder> lsSSupplierStockholderOld = sSupplierStockholderService.selectList(wrapperSSupplierStockholder);
            if (suppliersDetailVo.getLstSuppliersStockHolderVO() != null &&
                    suppliersDetailVo.getLstSuppliersStockHolderVO().size() != 0) {
                List<SSupplierStockholder> lsSSupplierStockholder = ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersStockHolderVO(), SSupplierStockholder.class);
                //比较
                List<SSupplierStockholder> lsSSupplierStockholderOldCopy = new ArrayList<>();
                lsSSupplierStockholderOldCopy.addAll(lsSSupplierStockholderOld);
                for (SSupplierStockholder objNew : lsSSupplierStockholder) {
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                    } else {
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
                    }
                    objNew.setSuppliersId(sSuppliers.getId());
                    boolean isNew = true;
                    for (int i = lsSSupplierStockholderOld.size() - 1; i >= 0; i--) {
                        SSupplierStockholder objOld = lsSSupplierStockholderOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSSupplierStockholderOldCopy.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SSupplierStockholder oldCopy : lsSSupplierStockholderOldCopy) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierStockholderService.updateById(oldCopy);
                }
                sSupplierStockholderService.insertOrUpdateAllColumnBatch(lsSSupplierStockholder);
            } else {
                for (SSupplierStockholder oldCopy : lsSSupplierStockholderOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierStockholderService.updateById(oldCopy);
                }
            }

            //保存or更新供方基本情况-联系方式
            EntityWrapper wrapperSSupplierContactInfo = new EntityWrapper<>();
            SSupplierContactInfo sSupplierContactInfo = new SSupplierContactInfo();
            sSupplierContactInfo.setSuppliersId(sSuppliers.getId());
            wrapperSSupplierContactInfo.setEntity(sSupplierContactInfo);
            List<SSupplierContactInfo> lsSSupplierContactInfoOld = sSupplierContactInfoService.selectList(wrapperSSupplierContactInfo);
            if (suppliersDetailVo.getLstSuppliersContactInfoVO() != null &&
                    suppliersDetailVo.getLstSuppliersContactInfoVO().size() != 0) {
                List<SSupplierContactInfo> lsSSupplierContactInfo = ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersContactInfoVO(), SSupplierContactInfo.class);
                //比较
                List<SSupplierContactInfo> lsSSupplierContactInfoOldCopy = new ArrayList<>();
                lsSSupplierContactInfoOldCopy.addAll(lsSSupplierContactInfoOld);
                for (SSupplierContactInfo objNew : lsSSupplierContactInfo) {
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                    } else {
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
                    }
                    objNew.setSuppliersId(sSuppliers.getId());
                    boolean isNew = true;
                    for (int i = lsSSupplierContactInfoOld.size() - 1; i >= 0; i--) {
                        SSupplierContactInfo objOld = lsSSupplierContactInfoOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSSupplierContactInfoOldCopy.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SSupplierContactInfo oldCopy : lsSSupplierContactInfoOldCopy) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierContactInfoService.updateById(oldCopy);
                }
                sSupplierContactInfoService.insertOrUpdateAllColumnBatch(lsSSupplierContactInfo);
            } else {
                for (SSupplierContactInfo oldCopy : lsSSupplierContactInfoOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierContactInfoService.updateById(oldCopy);
                }
            }

            //保存or更新供方基本情况--获取信息类型
            EntityWrapper wrapperSSupplierObtainInformation = new EntityWrapper<>();
            SSupplierObtainInformation entrySSupplierObtainInformation = new SSupplierObtainInformation();
            entrySSupplierObtainInformation.setSuppliersId(sSuppliers.getId());
            entrySSupplierObtainInformation.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierObtainInformation.setEntity(entrySSupplierObtainInformation);
            SSupplierObtainInformation sSupplierObtainInformationOld = sSupplierObtainInformationService.selectOne(wrapperSSupplierObtainInformation);
            if (suppliersDetailVo.getSuppliersObtainInformationVO() != null) {
                SSupplierObtainInformation sSupplierObtainInformation = new SSupplierObtainInformation();
                BeanUtils.copyProperties(suppliersDetailVo.getSuppliersObtainInformationVO(), sSupplierObtainInformation);
                sSupplierObtainInformation.setSuppliersId(sSuppliers.getId());
                if (StringUtils.isEmpty(sSupplierObtainInformation.getId())) {
                    sSupplierObtainInformation.setId(IdGen.uuid());
                    sSupplierObtainInformation.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                } else {
                    sSupplierObtainInformation.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
                }
                //比较
                compare(sSupplierObtainInformation, sSupplierObtainInformationOld, sSupplierObtainInformation.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                sSupplierObtainInformationService.insertOrUpdate(sSupplierObtainInformation);
            } else {
                if (sSupplierObtainInformationOld != null) {
                    compare(null, sSupplierObtainInformationOld, sSupplierObtainInformationOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    sSupplierObtainInformationOld.setUpdateBy(userId);
                    sSupplierObtainInformationOld.setUpdateDate(new Date());
                    sSupplierObtainInformationOld.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierObtainInformationService.updateById(sSupplierObtainInformationOld);
                }
            }

            //保存or更新供方基本情况--关联母公司信息
            EntityWrapper wrapperSSupplierRelateParentCmpy = new EntityWrapper<>();
            SSupplierRelateParentCmpy entrySSupplierRelateParentCmpy = new SSupplierRelateParentCmpy();
            entrySSupplierRelateParentCmpy.setSuppliersId(sSuppliers.getId());
            entrySSupplierRelateParentCmpy.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierRelateParentCmpy.setEntity(entrySSupplierRelateParentCmpy);
            List<SSupplierRelateParentCmpy> sSupplierRelateParentCmpyOldls = sSupplierRelateParentCmpyService.selectList(wrapperSSupplierRelateParentCmpy);
//            if(sSupplierRelateParentCmpyOldls!=null&&sSupplierRelateParentCmpyOldls.size()>1){
//                throw new RuntimeException("母公司数据异常");
//            }
            SSupplierRelateParentCmpy sSupplierRelateParentCmpyOld = new SSupplierRelateParentCmpy();
            if (sSupplierRelateParentCmpyOldls != null && sSupplierRelateParentCmpyOldls.size() == 1)
                sSupplierRelateParentCmpyOld = sSupplierRelateParentCmpyOldls.get(0);
            if (suppliersDetailVo.getSuppliersRelateParentCmpyVO() != null) {
                SSupplierRelateParentCmpy sSupplierRelateParentCmpy = new SSupplierRelateParentCmpy();
                if (suppliersDetailVo.getSuppliersRelateParentCmpyVO().getHasRelateParentCompany() != null &&
                        suppliersDetailVo.getSuppliersRelateParentCmpyVO().getHasRelateParentCompany() == CommonConstants.YES_INTEGER) {
                    BeanUtils.copyProperties(suppliersDetailVo.getSuppliersRelateParentCmpyVO(), sSupplierRelateParentCmpy);
                } else {
                    sSupplierRelateParentCmpy.setHasRelateParentCompany(CommonConstants.NO_INTEGER);
                    sSupplierRelateParentCmpy.setCreditLicenseCodeFlag(suppliersDetailVo.getSuppliersRelateParentCmpyVO().getCreditLicenseCodeFlag());
                }
                sSupplierRelateParentCmpy.setSuppliersId(sSuppliers.getId());
                if (StringUtils.isEmpty(sSupplierRelateParentCmpyOld.getId())) {
                    sSupplierRelateParentCmpy.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                } else {
                    sSupplierRelateParentCmpy.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
                    sSupplierRelateParentCmpy.setId(sSupplierRelateParentCmpyOld.getId());
                }
                //比较
                compare(sSupplierRelateParentCmpy, sSupplierRelateParentCmpyOld, sSupplierRelateParentCmpy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                sSupplierRelateParentCmpyService.insertOrUpdate(sSupplierRelateParentCmpy);
            }

            //保存or更新供方基本情况--银行账号
            EntityWrapper wrapperSSupplierBankAccount = new EntityWrapper<>();
            SSupplierBankAccount entrySSupplierBankAccount = new SSupplierBankAccount();
            entrySSupplierBankAccount.setSuppliersId(sSuppliers.getId());
            entrySSupplierBankAccount.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            wrapperSSupplierBankAccount.setEntity(entrySSupplierBankAccount);
            List<SSupplierBankAccount> oldLstBankAccount = sSupplierBankAccountService.selectList(wrapperSSupplierBankAccount);
            List<SuppliersBankAccountVO> lstBankAccountVO = suppliersDetailVo.getLstSuppliersBankAccountVO();
            List<String> bankAccountIds = lstBankAccountVO.stream().map(SuppliersBankAccountVO::getId).collect(Collectors.toList());
            if (lstBankAccountVO != null && lstBankAccountVO.size() > 0) {
                lstBankAccountVO.forEach(item -> {


                    SSupplierBankAccount bankAccountVo = new SSupplierBankAccount();
                    bankAccountVo.setSuppliersId(sSuppliers.getId());
                    bankAccountVo.setAccountNumber(item.getAccountNumber());
                    bankAccountVo.setAccountType(item.getAccountType());
                    bankAccountVo.setBankName(item.getBankName());
                    bankAccountVo.setBankNumber(item.getBankNumber());
                    bankAccountVo.setId(item.getId());
                    bankAccountVo.setBaseFeilds(UserUtils.getCurrentUserId(), "", CommonConstants.DEL_FLAG_NORMAL, StringUtils.isEmpty(item.getId()));
                    sSupplierBankAccountService.insertOrUpdate(bankAccountVo);
                });
            }

            if (oldLstBankAccount != null && oldLstBankAccount.size() > 0) {
                //数据库存在，但提交的数据不存在了，则进行逻辑删除操作
                List<SSupplierBankAccount> delList = oldLstBankAccount.stream().filter(item -> !bankAccountIds.contains(item.getId())).collect(Collectors.toList());
                delList.forEach(item -> {
                    item.setBaseFeilds(UserUtils.getCurrentUserId(), "", CommonConstants.DEL_FLAG_DELETE, false);
                    sSupplierBankAccountService.updateById(item);
                });

            }

            //保存or更新供方基本情况--业务状况
            EntityWrapper wrapperSSupplierBusinessSituation = new EntityWrapper<>();
            SSupplierBusinessSituation entrySSupplierBusinessSituation = new SSupplierBusinessSituation();
            entrySSupplierBusinessSituation.setSuppliersId(sSuppliers.getId());
            wrapperSSupplierBusinessSituation.setEntity(entrySSupplierBusinessSituation);
            SSupplierBusinessSituation sSupplierBusinessSituationold = sSupplierBusinessSituationService.selectOne(wrapperSSupplierBusinessSituation);
            if (suppliersDetailVo.getSuppliersBusinessSituationVO() != null) {
                SSupplierBusinessSituation sSupplierBusinessSituation = new SSupplierBusinessSituation();
                BeanUtils.copyProperties(suppliersDetailVo.getSuppliersBusinessSituationVO(), sSupplierBusinessSituation);
                sSupplierBusinessSituation.setSuppliersId(sSuppliers.getId());
                if (StringUtils.isEmpty(sSupplierBusinessSituation.getId())) {
                    sSupplierBusinessSituation.setId(IdGen.uuid());
                    sSupplierBusinessSituation.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                } else {
                    sSupplierBusinessSituation.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
                }
                //比较
                compare(sSupplierBusinessSituation, sSupplierBusinessSituationold, sSupplierBusinessSituation.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                sSupplierBusinessSituationService.insertOrUpdateAllColumn(sSupplierBusinessSituation);
            } else {
                if (sSupplierBusinessSituationold != null) {
                    compare(null, sSupplierBusinessSituationold, sSupplierBusinessSituationold.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    sSupplierBusinessSituationold.setUpdateBy(userId);
                    sSupplierBusinessSituationold.setUpdateDate(new Date());
                    sSupplierBusinessSituationold.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSupplierBusinessSituationService.updateById(sSupplierBusinessSituationold);
                }
            }

            //保存or更新供方近三年业绩-战略合作+一般合作
            EntityWrapper wrapperSSuppliersLastThreeAchieve = new EntityWrapper<>();
            SSuppliersLastThreeAchieve sSuppliersLastThreeAchieve = new SSuppliersLastThreeAchieve();
            sSuppliersLastThreeAchieve.setSuppliersId(sSuppliers.getId());
            sSuppliersLastThreeAchieve.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            sSuppliersLastThreeAchieve.setSourceType(CommonConstants.EXTERNAL);
            wrapperSSuppliersLastThreeAchieve.setEntity(sSuppliersLastThreeAchieve);
            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveOld = sSuppliersLastThreeAchieveService.selectList(wrapperSSuppliersLastThreeAchieve);
            List<SuppliersLastThreeMajorAchievenVO> lstSuppliersLastThreeMajorAchievenVO = suppliersDetailVo.getLstSuppliersLastThreeMajorAchievenVO();
            List<SuppliersLastThreeCommonAchievenVO> lstSuppliersLastThreeCommonAchievenVO = suppliersDetailVo.getLstSuppliersLastThreeCommonAchievenVO();
            if (lsSSuppliersLastThreeAchieveOld == null) lsSSuppliersLastThreeAchieveOld = new ArrayList<>();
            if (lstSuppliersLastThreeMajorAchievenVO == null) lstSuppliersLastThreeMajorAchievenVO = new ArrayList<>();
            if (lstSuppliersLastThreeCommonAchievenVO == null)
                lstSuppliersLastThreeCommonAchievenVO = new ArrayList<>();
            Map<Integer, List<AttachmentVO>> attachmentVOmap = suppliersDetailVo.getMapAttachmentVOs();
            if (attachmentVOmap == null) attachmentVOmap = new HashMap<Integer, List<AttachmentVO>>();
            List<AttachmentVO> lstAttachment = new ArrayList<>();

            for (int i = lstSuppliersLastThreeMajorAchievenVO.size() - 1; i >= 0; i--) {
                SuppliersLastThreeMajorAchievenVO obj = lstSuppliersLastThreeMajorAchievenVO.get(i);
                if (StringUtils.isEmpty(obj.getCooperativeUnitName())) {
                    lstSuppliersLastThreeMajorAchievenVO.remove(obj);
                }
                obj.setCooperativeType(CommonConstants.MAJOR_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
                String uuid = IdGen.uuid();
                if (StringUtils.isEmpty(obj.getId())) {
                    obj.setId(uuid);
                }
                List<AttachmentVO> ls = obj.getLstattachmentVO();
                if (ls != null && ls.size() > 0) {
                    for (AttachmentVO attachmentVO : ls) {
                        attachmentVO.setFormId(sSuppliers.getId());
                        attachmentVO.setRelatedId(obj.getId());
                        attachmentVO.setAttachmentType(1);
                    }
                    lstAttachment.addAll(ls);
                }
            }
            for (int i = lstSuppliersLastThreeCommonAchievenVO.size() - 1; i >= 0; i--) {
                SuppliersLastThreeCommonAchievenVO obj = lstSuppliersLastThreeCommonAchievenVO.get(i);
                if (StringUtils.isEmpty(obj.getCooperativeUnitName())) {
                    lstSuppliersLastThreeCommonAchievenVO.remove(obj);
                }
                obj.setCooperativeType(CommonConstants.COMMON_COOPRATIVE);//合作类型（1：一般合作，2：战略合作）
                String uuid = IdGen.uuid();
                if (StringUtils.isEmpty(obj.getId())) {
                    obj.setId(uuid);
                }
                List<AttachmentVO> ls = obj.getLstattachmentVO();
                if (ls != null && ls.size() > 0) {
                    for (AttachmentVO attachmentVO : ls) {
                        attachmentVO.setFormId(sSuppliers.getId());
                        attachmentVO.setRelatedId(obj.getId());
                        attachmentVO.setAttachmentType(1);
                    }
                    lstAttachment.addAll(ls);
                }
            }
            if (lstAttachment != null && lstAttachment.size() > 0)
                attachmentVOmap.put(1, lstAttachment);//添加1：供方三年业绩合同附件
            suppliersDetailVo.setMapAttachmentVOs(attachmentVOmap);

            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieve = new ArrayList<>();
            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveMajor = ListObjCopyUtil.copyTo(lstSuppliersLastThreeMajorAchievenVO, SSuppliersLastThreeAchieve.class);
            List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveCommon = ListObjCopyUtil.copyTo(lstSuppliersLastThreeCommonAchievenVO, SSuppliersLastThreeAchieve.class);
            lsSSuppliersLastThreeAchieve.addAll(lsSSuppliersLastThreeAchieveMajor);
            lsSSuppliersLastThreeAchieve.addAll(lsSSuppliersLastThreeAchieveCommon);
            if (lsSSuppliersLastThreeAchieve != null &&
                    lsSSuppliersLastThreeAchieve.size() != 0) {
                //List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieve=ListObjCopyUtil.copyTo(suppliersDetailVo.getLstSuppliersLastThreeAchievenVO(),SSuppliersLastThreeAchieve.class);
                //比较
                List<SSuppliersLastThreeAchieve> lsSSuppliersLastThreeAchieveOldCopy = new ArrayList<>();
                lsSSuppliersLastThreeAchieveOldCopy.addAll(lsSSuppliersLastThreeAchieveOld);
                for (SSuppliersLastThreeAchieve objNew : lsSSuppliersLastThreeAchieve) {
                    objNew.setSuppliersId(sSuppliers.getId());
                    objNew.setSourceType(CommonConstants.EXTERNAL);
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                    } else {
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
                    }
                    boolean isNew = true;
                    for (int i = lsSSuppliersLastThreeAchieveOld.size() - 1; i >= 0; i--) {
                        SSuppliersLastThreeAchieve objOld = lsSSuppliersLastThreeAchieveOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSSuppliersLastThreeAchieveOldCopy.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SSuppliersLastThreeAchieve oldCopy : lsSSuppliersLastThreeAchieveOldCopy) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSuppliersLastThreeAchieveService.updateById(oldCopy);
                }
                sSuppliersLastThreeAchieveService.insertOrUpdateAllColumnBatch(lsSSuppliersLastThreeAchieve);
            } else {
                for (SSuppliersLastThreeAchieve oldCopy : lsSSuppliersLastThreeAchieveOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sSuppliersLastThreeAchieveService.updateById(oldCopy);
                }
            }

            //保存or更新附件
//            EntityWrapper sAttachmentWrapper = new EntityWrapper<>();
//            SAttachment sAttachmentEntry = new SAttachment();
//            sAttachmentEntry.setFormId(sSuppliers.getId());
//            sAttachmentEntry.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
//            sAttachmentWrapper.setEntity(sAttachmentEntry);
//            List<SAttachment> lsSAttachmentOld = sAttachmentService.selectList(sAttachmentWrapper);

            Map<String, Object> mapParams = new HashMap<String, Object>();
            mapParams.put("formId", sSuppliers.getId());
            mapParams.put("lstNotInType", new Integer[]{AttachmentTypeEnum.ATTACHMENT_TYPE_13.getCode(), AttachmentTypeEnum.ATTACHMENT_TYPE_14.getCode()});
            List<ExtSAttachment> lsSAttachmentOld = sAttachmentService.getSAttachmentByCnd(mapParams);
            if (suppliersDetailVo.getMapAttachmentVOs() != null &&
                    suppliersDetailVo.getMapAttachmentVOs().size() != 0) {
                Map<Integer, List<AttachmentVO>> map = suppliersDetailVo.getMapAttachmentVOs();

                List<SAttachment> lsSAttachmentOldCopy = new ArrayList<>();
                lsSAttachmentOldCopy.addAll(lsSAttachmentOld);
                List<SAttachment> lsSAttachment = new ArrayList<>();
                for (List<AttachmentVO> ls : map.values()) {
                    lsSAttachment.addAll(ListObjCopyUtil.copyTo(ls, SAttachment.class));
                }
                //比较

                for (SAttachment objNew : lsSAttachment) {
                    if (StringUtils.isEmpty(objNew.getId())) {
                        objNew.setId(IdGen.uuid());
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                    } else {
                        objNew.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
                    }
                    objNew.setFormId(sSuppliers.getId());
//					objNew.setRelatedId(sSuppliers.getId());
                    boolean isNew = true;
                    for (int i = lsSAttachmentOld.size() - 1; i >= 0; i--) {
                        SAttachment objOld = lsSAttachmentOld.get(i);
                        if (objNew.getId().equals(objOld.getId())) {
                            lsSAttachmentOld.remove(objOld);
                            compare(objNew, objOld, objOld.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                        compare(objNew, null, objNew.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                }
                for (SAttachment oldCopy : lsSAttachmentOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sAttachmentService.updateById(oldCopy);
                }
                if (lsSAttachment != null && lsSAttachment.size() > 0)
                    sAttachmentService.insertOrUpdateAllColumnBatch(lsSAttachment);
            } else {
                for (SAttachment oldCopy : lsSAttachmentOld) {
                    compare(null, oldCopy, oldCopy.getId(), sSuppliers.getId(), sSupplierRcRelateStatus, userId);
                    oldCopy.setUpdateBy(userId);
                    oldCopy.setUpdateDate(new Date());
                    oldCopy.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
                    sAttachmentService.updateById(oldCopy);
                }
            }
            if (sSupplierRcRelateStatus != null && SupplierStatusEnum.QUALIFIED.getCode().equals(sSupplierRcRelateStatus.getSupplierStatus() + "")) {
                //默认同意
                fallbackSuppliers(sSuppliers.getId(), EnumConstant.AuditStatus.agree.getCode(), "");
            }

            hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS, "修改成功");
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("系统错误");
        }
        return hResult;
    }

    /**
     * 审核供方信息
     *
     * @param supplierId 供方id
     * @param actionType 1通过 2拒绝
     * @return
     */
    public RestReturnResult<Object> fallbackSuppliers(String supplierId, Integer actionType, String sHistoryCommentId) {
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, supplierId, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
        try {
            SSuppliers sSuppliers = super.selectById(supplierId);
            if (sSuppliers == null) {
                throw new RuntimeException("供方信息不存在!");
            }
            //改为已修改
            sSuppliers.setModifiedFlag(CommonConstants.NO_INTEGER);
            sSuppliers.setUpdateDate(new Date());
            this.updateById(sSuppliers);
            if (EnumConstant.AuditStatus.reject.getCode() == actionType) {//审核拒绝
                //修改
                EntityWrapper updateWrapper = new EntityWrapper<>();
                SSupplierFormModifyMapping updateSSupplierFormModifyMapping = new SSupplierFormModifyMapping();
                updateSSupplierFormModifyMapping.setSuppliersId(supplierId);
                updateSSupplierFormModifyMapping.setDongFlag(CommonConstants.UNDONG_FLAG);//是否处理（0：否，1：是）
                updateSSupplierFormModifyMapping.setActionType(EnumConstant.actionType.update.getCode());//处理类型（1：新增，2：修改，3：删除）
                updateSSupplierFormModifyMapping.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
                updateWrapper.setEntity(updateSSupplierFormModifyMapping);
                List<SSupplierFormModifyMapping> sSupplierFormModifyMappingls = sSupplierFormModifyMappingService.selectList(updateWrapper);
                if (sSupplierFormModifyMappingls != null && sSupplierFormModifyMappingls.size() > 0)
                    extSSupplierFormModifyMappingMapper.updateBatch(sSupplierFormModifyMappingls);

                //删除
                List<ExtSSupplierFormModifyMapping> ls = extSSupplierFormModifyMappingMapper.getClassRecordIdByType(EnumConstant.actionType.delete.getCode(), supplierId);
                for (ExtSSupplierFormModifyMapping extSSupplierFormModifyMapping : ls) {
                    EntityWrapper wrapper = new EntityWrapper<>();
                    SSupplierFormModifyMapping sSupplierFormModifyMapping = new SSupplierFormModifyMapping();
                    sSupplierFormModifyMapping.setClassRecordId(extSSupplierFormModifyMapping.getClassRecordId());
                    sSupplierFormModifyMapping.setDongFlag(CommonConstants.UNDONG_FLAG);//是否处理（0：否，1：是）
                    sSupplierFormModifyMapping.setActionType(EnumConstant.actionType.delete.getCode());//处理类型（1：新增，2：修改，3：删除）
                    sSupplierFormModifyMapping.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
                    wrapper.setEntity(sSupplierFormModifyMapping);
                    List<SSupplierFormModifyMapping> sSupplierFormModifyMappinglsDelete = sSupplierFormModifyMappingService.selectList(wrapper);
                    String tableName = "";
                    String updateSet = "";
                    for (SSupplierFormModifyMapping obj : sSupplierFormModifyMappinglsDelete) {
                        if (StringUtils.isEmpty(tableName)) tableName = obj.getTableName();
                        String bv = obj.getModifiedBeforeValue() == null ? "''" : ("'" + obj.getModifiedBeforeValue() + "'");
                        updateSet = updateSet + obj.getTableFieldName() + "=" + bv + ",";
                    }
                    if (StringUtils.isNotEmpty(tableName)) {
                        updateSet += "del_flag=0";
                        if (tableName.toLowerCase().equals("s_attachment")) {
                        } else {
                            updateSet += ",suppliers_id='" + supplierId + "'";
                        }
                        extSSupplierFormModifyMappingMapper.updateData(tableName, updateSet, extSSupplierFormModifyMapping.getClassRecordId());
                    }
                }

                //新增
                List<ExtSSupplierFormModifyMapping> lsAdd = extSSupplierFormModifyMappingMapper.getClassRecordIdByType(EnumConstant.actionType.add.getCode(), supplierId);
                for (ExtSSupplierFormModifyMapping extSSupplierFormModifyMapping : lsAdd) {
                    extSSupplierFormModifyMappingMapper.deleteByPrimaryKey(extSSupplierFormModifyMapping.getTableName(), extSSupplierFormModifyMapping.getClassRecordId());
                }

                //关联关系表
                //意向公司关系表更新
//                EntityWrapper sSupplierRcRelateWrapper = new EntityWrapper<>();
//                SSupplierRcRelate sSupplierRcRelate = new SSupplierRcRelate();
//                sSupplierRcRelate.setSuppliersId(supplierId);
//                sSupplierRcRelateWrapper.setEntity(sSupplierRcRelate);
//                sSupplierRcRelateService.delete(sSupplierRcRelateWrapper);
//                String intentionRegionalCompanyIds = sSuppliers.getIntentionRegionalCompanyIds();
//                if (StringUtils.isNotEmpty(intentionRegionalCompanyIds)) {
//                    String[] intentionRegionalCompanyIdArr = intentionRegionalCompanyIds.split(",");
//                    List<SSupplierRcRelate> sSupplierRcRelatels = new ArrayList();
//                    for (String intentionRegionalCompanyId : intentionRegionalCompanyIdArr) {
//                        SSupplierRcRelate obj = new SSupplierRcRelate();
//                        obj.setId(IdGen.uuid());
//                        obj.setSuppliersId(sSuppliers.getId());
//                        obj.setRegionalCompanyId(intentionRegionalCompanyId);
//                        obj.setSupplierCategoryIds(sSuppliers.getSupplierCategoryIds());
//                        obj.setSupplierServiceCategoryIds(sSuppliers.getSupplierServiceCategoryIds());
//                        obj.setSupplierStatus(Integer.parseInt(SupplierStatusEnum.QUALIFIED.getCode()));
//                        obj.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
//                        sSupplierRcRelatels.add(obj);
//                    }
//                    sSupplierRcRelateService.insertBatch(sSupplierRcRelatels);
//                }


                //供方基本情况-供方分类关系表更新
                EntityWrapper sSupplierCategoryRelateWrapper = new EntityWrapper<>();
                SSupplierCategoryRelate sSupplierCategoryRelate = new SSupplierCategoryRelate();
                sSupplierCategoryRelate.setSuppliersId(sSuppliers.getId());
                sSupplierCategoryRelateWrapper.setEntity(sSupplierCategoryRelate);
                sSupplierCategoryRelateService.delete(sSupplierCategoryRelateWrapper);
                String supplierCategoryIds = sSuppliers.getSupplierCategoryIds();
                if (StringUtils.isNotEmpty(supplierCategoryIds)) {
                    String[] supplierCategoryIdArr = supplierCategoryIds.split(",");
                    List<SSupplierCategoryRelate> sSupplierCategoryRelateLs = new ArrayList<>();
                    for (String supplierCategoryId : supplierCategoryIdArr) {
                        SSupplierCategoryRelate obj = new SSupplierCategoryRelate();
                        obj.setId(IdGen.uuid());
                        obj.setSuppliersId(sSuppliers.getId());
                        obj.setCategoryId(supplierCategoryId);
                        obj.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, true);
                        sSupplierCategoryRelateLs.add(obj);
                    }
                    if (sSupplierCategoryRelateLs != null && sSupplierCategoryRelateLs.size() > 0)
                        sSupplierCategoryRelateService.insertBatch(sSupplierCategoryRelateLs);
                }
            }
            EntityWrapper updateWrapper = new EntityWrapper<>();
            SSupplierFormModifyMapping updateSSupplierFormModifyMapping = new SSupplierFormModifyMapping();
            updateSSupplierFormModifyMapping.setSuppliersId(supplierId);
            updateSSupplierFormModifyMapping.setDongFlag(CommonConstants.UNDONG_FLAG);//是否处理（0：否，1：是）
            updateSSupplierFormModifyMapping.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
            updateWrapper.setEntity(updateSSupplierFormModifyMapping);
            List<SSupplierFormModifyMapping> sSupplierFormModifyMappingls = sSupplierFormModifyMappingService.selectList(updateWrapper);
            List<SSuppliersModifiedHistory> sSuppliersModifiedHistoryLs = new ArrayList<>();
            Date nowDate = new Date();
            for (SSupplierFormModifyMapping sSupplierFormModifyMapping : sSupplierFormModifyMappingls) {
                if (CommonConstants.HIDDEN_FLAG == sSupplierFormModifyMapping.getShowFlag()) continue;
                SSuppliersModifiedHistory sSuppliersModifiedHistory = new SSuppliersModifiedHistory();
                sSuppliersModifiedHistory.setId(IdGen.uuid());
                sSuppliersModifiedHistory.setSuppliersId(supplierId);
                sSuppliersModifiedHistory.setFieldName(sSupplierFormModifyMapping.getClassFieldName());
                sSuppliersModifiedHistory.setModifiedBeforeValue(sSupplierFormModifyMapping.getModifiedBeforeName());
                sSuppliersModifiedHistory.setModifiedAfterValue(sSupplierFormModifyMapping.getModifiedAfterName());
                sSuppliersModifiedHistory.setAuditUserId(UserUtils.getCurrentUserId());
                if (EnumConstant.AuditStatus.reject.getCode() == actionType) {
                    sSuppliersModifiedHistory.setAuditStatusName(EnumConstant.AuditStatus.reject.getDesc());
                } else {
                    sSuppliersModifiedHistory.setAuditStatusName(EnumConstant.AuditStatus.agree.getDesc());
                }
                sSuppliersModifiedHistory.setAuditTime(nowDate);
                sSuppliersModifiedHistory.setCreateBy(sSupplierFormModifyMapping.getCreateBy());
                sSuppliersModifiedHistory.setCreateDate(sSupplierFormModifyMapping.getCreateDate());
                sSuppliersModifiedHistory.setBaseFeilds(UserUtils.getCurrentUserId(), null, 0, false);
                sSuppliersModifiedHistoryLs.add(sSuppliersModifiedHistory);
            }
            if (sSuppliersModifiedHistoryLs != null && sSuppliersModifiedHistoryLs.size() > 0)
                sSuppliersModifiedHistoryService.insertBatch(sSuppliersModifiedHistoryLs);

            extSSupplierFormModifyMappingMapper.updateDoneFlag(supplierId, sHistoryCommentId);

            hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS, supplierId);
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("----------------变更审核-----e---------:" + e.getMessage());
            throw new RuntimeException(e.getMessage());
        }
        return hResult;
    }

    @Override
    public SSuppliers getById(String id) {
        SSuppliers sSuppliers = extSSuppliersMapper.getById(id);
        return sSuppliers;
    }


    /**
     * 供方列表-潜在列表(分页)
     *
     * @param suppliersVO
     * @return
     */
    @Override
    public RestReturnResult getSuppliersMulitList(SuppliersRequestVO suppliersVO) {
        RestReturnResult restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[0], CommonConstants.ERROR_CODES[0]);
        try {
            PageCode pageCode = new PageCode(suppliersVO.getPageNumber(), suppliersVO.getPageSize());

            Map<String, Object> map = new HashMap<String, Object>();
            map.put("companyName", suppliersVO.getCompanyName());
            map.put("intentionRegionalCompanyIds", suppliersVO.getIntentionRegionalCompanyIds());
            if (suppliersVO.getSupplierStatus() == null) {
                String[] statuses = CommonConstants.SUPPLIER_STATUS_POTENTIAL.split(",");
//                List<Integer> supplierStatus = new ArrayList<>();
//                supplierStatus.add(2);
//                supplierStatus.add(3);
//                supplierStatus.add(4);
//                supplierStatus.add(5);
//                supplierStatus.add(6);
                map.put("supplierStatus", statuses);//潜在列表所有数据
            } else {
                List<Integer> supplierStatus = new ArrayList<>();
                supplierStatus.add(suppliersVO.getSupplierStatus());
                map.put("supplierStatus", supplierStatus);
            }
            map.put("registerStartTime", suppliersVO.getRegisterStartTime());
            map.put("registerEndTime", suppliersVO.getRegisterEndTime());
            map.put("supplierCategoryIds", suppliersVO.getSupplierCategoryIds());

            pageCode.setCount(extSSuppliersMapper.getSuppliersMulitListCounts(map));

            map.put("currentRecordNum", (pageCode.getPageNo() - 1) * pageCode.getPageSize());
            map.put("pageSize", pageCode.getPageSize());

            List<ExtSSuppliers> ls = extSSuppliersMapper.getSuppliersMulitList(map);
            List<SuppliersResponseVO> result = this.transferTO(ls);
            pageCode.setList(result);

            restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, pageCode);
        } catch (Exception e) {
            e.printStackTrace();
            restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[1], CommonConstants.ERROR_CODES[1]);
        }

        return restReturnResult;
    }

    /**
     * 供方列表-黑库列表(分页)
     *
     * @param suppliersVO
     * @return
     */
    @Override
    public RestReturnResult getSuppliersBlackList(SuppliersRequestVO suppliersVO) {
        RestReturnResult restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[0], CommonConstants.ERROR_CODES[0]);
        try {
            if (suppliersVO.getPageFlag() != null &&
                    suppliersVO.getPageFlag() == CommonConstants.YES_INTEGER) {
                PageCode pageCode = new PageCode(suppliersVO.getPageNumber(), suppliersVO.getPageSize());

                Map<String, Object> map = new HashMap<String, Object>();
                map.put("companyName", suppliersVO.getCompanyName());
                map.put("intentionRegionalCompanyIds", suppliersVO.getIntentionRegionalCompanyIds());
                if (suppliersVO.getSupplierStatus() != null) {
                    map.put("supplierStatus", suppliersVO.getSupplierStatus());
                }
                map.put("supplierBigStatus", SupplierBigStatusEnum.BLACK_LIBRARY.getCode());
                map.put("turnToBlackLibraryStartTime", suppliersVO.getTurnToBlackLibraryStartTime());
                map.put("turnToBlackLibraryEndTime", suppliersVO.getTurnToBlackLibraryEndTime());
//            map.put("supplierCategoryIds", suppliersVO.getSupplierCategoryIds());
                map.put("orderBy", " sup.turn_to_black_library_time desc ");
                pageCode.setCount(extSSuppliersMapper.getSuppliersBlackListCounts(map));

                map.put("currentRecordNum", (pageCode.getPageNo() - 1) * pageCode.getPageSize());
                map.put("pageSize", pageCode.getPageSize());

                List<ExtSSuppliers> ls = extSSuppliersMapper.getSuppliersBlackList(map);
                List<SuppliersResponseVO> result = this.transferTO(ls);
                pageCode.setList(result);

                restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, pageCode);
            } else {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("companyName", suppliersVO.getCompanyName());
                map.put("intentionRegionalCompanyIds", suppliersVO.getIntentionRegionalCompanyIds());
                if (suppliersVO.getSupplierStatus() != null) {
                    map.put("supplierStatus", suppliersVO.getSupplierStatus());
                }
                map.put("supplierBigStatus", SupplierBigStatusEnum.BLACK_LIBRARY.getCode());
                map.put("turnToBlackLibraryStartTime", suppliersVO.getTurnToBlackLibraryStartTime());
                map.put("turnToBlackLibraryEndTime", suppliersVO.getTurnToBlackLibraryEndTime());
//            map.put("supplierCategoryIds", suppliersVO.getSupplierCategoryIds());
                map.put("orderBy", " sup.update_date desc ");
                map.put("pageSize", 0);
                List<ExtSSuppliers> ls = extSSuppliersMapper.getSuppliersBlackList(map);
                List<SuppliersResponseVO> result = this.transferTO(ls);
                restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, result);
            }
        } catch (Exception e) {
            e.printStackTrace();
            restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[1], CommonConstants.ERROR_CODES[1]);
        }

        return restReturnResult;
    }


    private List<SuppliersResponseVO> transferTO(List<ExtSSuppliers> list) {

        List<SuppliersResponseVO> resultList = null;

        if (list != null && list.size() > 0) {
            resultList = new ArrayList<SuppliersResponseVO>();
            SuppliersResponseVO suppliersVO = null;
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("dict_type", "supplier_status");
            List<SysDict> statusList = sysDictService.selectByMap(map);
            Map<String, String> dictMap = new HashMap<>();
            if (statusList != null && statusList.size() > 0) {
                for (SysDict dict : statusList) {
                    dictMap.put(dict.getDictValue(), dict.getDictLabel());
                }
            }
            for (ExtSSuppliers extSSuppliers : list) {
                suppliersVO = new SuppliersResponseVO();

                //状态
                if (extSSuppliers.getSupplierStatus() != null) {
                    suppliersVO.setSupplierStatusName(dictMap.get(String.valueOf(extSSuppliers.getSupplierStatus())));
                }
                suppliersVO.setSupplierStatus(extSSuppliers.getSupplierStatus());
                suppliersVO.setId(extSSuppliers.getId());
                suppliersVO.setSupplierCategoryIds(extSSuppliers.getSupplierCategoryIds());
                suppliersVO.setIntentionRegionalCompanyIds(extSSuppliers.getIntentionRegionalCompanyIds());
                suppliersVO.setStarLevel(extSSuppliers.getStarLevel());
                //承接省份
                suppliersVO.setUndertakeAreas(extSSuppliers.getUndertakeAreas());
                String undertakeAreas = suppliersVO.getUndertakeAreas();
                if (StringUtils.isNotEmpty(undertakeAreas)) {
                    String[] idArr = undertakeAreas.split(",");
                    String names = sysAreaService.getAreaNames(idArr);
                    suppliersVO.setUndertakeAreasNames(names);
                }
                //供方名称
                suppliersVO.setCompanyName(extSSuppliers.getCompanyName());

                suppliersVO.setActionType(extSSuppliers.getActionType());

                //供方分类
                String supplierCategoryIds = extSSuppliers.getSupplierCategoryIds();
                if (supplierCategoryIds != null && supplierCategoryIds.length() > 0) {
                    String[] supplierCategoryIdArr = supplierCategoryIds.split(",");
                    String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                    suppliersVO.setSupplierCategoryNames(supplierCategoryNames);
                }

                //合格供方分类
                String supplierCategoryActualIds = extSSuppliers.getSupplierCategoryActualIds();
                if (supplierCategoryActualIds != null && supplierCategoryActualIds.length() > 0) {
                    String[] supplierCategoryIdArr = supplierCategoryActualIds.split(",");
                    String supplierCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierCategoryIdArr);
                    suppliersVO.setSupplierCategoryActualNames(supplierCategoryNames);
                }

                //意向地区公司
                String intentionRegionalCompanyIds = extSSuppliers.getIntentionRegionalCompanyIds();
                if (intentionRegionalCompanyIds != null && intentionRegionalCompanyIds.length() > 0) {
                    String[] intentionRegionalCompanyIdArr = intentionRegionalCompanyIds.split(",");
                    String intentionRegionalCompanyNames = sRegionalCompanyService.getRegionalCompanyNames(intentionRegionalCompanyIdArr);
                    suppliersVO.setIntentionRegionalCompanyNames(intentionRegionalCompanyNames);
                } else {
                    suppliersVO.setIntentionRegionalCompanyNames(extSSuppliers.getIntentionRegionalCompanyNames());
                }

                //服务地区公司
                String serviceRegionalCompanyIds = extSSuppliers.getServiceRegionalCompanyIds();
                if (serviceRegionalCompanyIds != null && serviceRegionalCompanyIds.length() > 0) {
                    String[] serviceRegionalCompanyIdArr = serviceRegionalCompanyIds.split(",");
                    String serviceRegionalCompanyNames = sRegionalCompanyService.getRegionalCompanyNames(serviceRegionalCompanyIdArr);
                    suppliersVO.setServiceRegionalCompanyNames(serviceRegionalCompanyNames);
                }
                suppliersVO.setServiceRegionalCompanyIds(extSSuppliers.getServiceRegionalCompanyIds());

                //注册时间
                suppliersVO.setRegisterTime(extSSuppliers.getRegisterTime());
                if (extSSuppliers.getRegisterTime() != null) {
                    suppliersVO.setRegisterTimeStr(DateUtils.formatDate(extSSuppliers.getRegisterTime()));
                }

                //入库时间
                suppliersVO.setStoredTime(extSSuppliers.getStoredTime());

                //转不合格时间
                suppliersVO.setUnqualifiedTime(extSSuppliers.getUnqualifiedTime());

                //转黑库时间
                suppliersVO.setTurnToBlackLibraryTime(extSSuppliers.getTurnToBlackLibraryTime());
                suppliersVO.setRcRelatedId(extSSuppliers.getRcRelatedId());
                //是否显示现场考察按钮
                if (extSSuppliers.getShowSiteInspection() != null && extSSuppliers.getShowSiteInspection() > 0) {
                    suppliersVO.setShowSiteInspection(CommonConstants.YES_INTEGER);
                } else {
                    suppliersVO.setShowSiteInspection(CommonConstants.NO_INTEGER);
                }
                resultList.add(suppliersVO);
            }
        }
        return resultList;
    }


//    @Override
//    public RestReturnResult getSuppliersList(SuppliersRequestVO suppliersVO) {
//        RestReturnResult restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[0], CommonConstants.ERROR_CODES[0]);
//        try {
//            PageCode pageCode = new PageCode(suppliersVO.getPageNumber(), suppliersVO.getPageSize());
//
//            Map<String, Object> map = new HashMap<String, Object>();
//            map.put("companyName", suppliersVO.getCompanyName());
//            map.put("intentionRegionalCompanyIds", suppliersVO.getIntentionRegionalCompanyIds());
//            map.put("supplierStatus", suppliersVO.getSupplierStatus());
//            map.put("registerStartTime", suppliersVO.getRegisterStartTime());
//            map.put("registerEndTime", suppliersVO.getRegisterEndTime());
//            map.put("supplierCategoryIds", suppliersVO.getSupplierCategoryIds());
//
//            map.put("serviceRegionalCompanyIds", suppliersVO.getServiceRegionalCompanyIds());//服务地区公司
//            //入库时间
//            map.put("storedStartTime", suppliersVO.getStoredStartTime());
//            map.put("storedEndTime", suppliersVO.getStoredEndTime());
//            //转不合格时间
//            map.put("unqualifiedStartTime", suppliersVO.getUnqualifiedStartTime());
//            map.put("unqualifiedEndTime", suppliersVO.getUnqualifiedEndTime());
//            //转黑库时间
//            map.put("turnToBlackLibraryStartTime", suppliersVO.getTurnToBlackLibraryStartTime());
//            map.put("turnToBlackLibraryEndTime", suppliersVO.getTurnToBlackLibraryEndTime());
//
//            //supplierType  1：待观察列表，2：不合格列表，3：合格列表，4：黑裤列表
//            map.put("supplierBigStatus", suppliersVO.getSupplierBigStatus());
//
//            pageCode.setCount(extSSuppliersMapper.getSuppliersListCounts(map));
//
//            map.put("currentRecordNum", (pageCode.getPageNo() - 1) * pageCode.getPageSize());
//            map.put("pageSize", pageCode.getPageSize());
//
//            List<ExtSSuppliers> ls = extSSuppliersMapper.getSuppliersList(map);
//            List<SuppliersResponseVO> result = this.transferTO(ls);
//            pageCode.setList(result);
//
//            restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, pageCode);
//        } catch (Exception e) {
//            e.printStackTrace();
//            restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[1], CommonConstants.ERROR_CODES[1]);
//        }
//
//        return restReturnResult;
//    }

    /**
     * 供方列表-其他列表(分页)
     *
     * @param suppliersVO
     * @return
     */
    @Override
    public RestReturnResult getSuppliersList(SuppliersRequestVO suppliersVO) {
        RestReturnResult restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[0], CommonConstants.ERROR_CODES[0]);
        try {
            if (suppliersVO.getPageFlag() != null &&
                    suppliersVO.getPageFlag() == CommonConstants.YES_INTEGER) {
                PageCode pageCode = new PageCode(suppliersVO.getPageNumber(), suppliersVO.getPageSize());

                Map<String, Object> map = new HashMap<String, Object>();
                map.put("companyName", suppliersVO.getCompanyName());
                map.put("intentionRegionalCompanyIds", suppliersVO.getIntentionRegionalCompanyIds());
                map.put("supplierStatus", suppliersVO.getSupplierStatus());
                map.put("registerStartTime", suppliersVO.getRegisterStartTime());
                map.put("registerEndTime", suppliersVO.getRegisterEndTime());
                map.put("supplierCategoryIds", suppliersVO.getSupplierCategoryIds());

                map.put("serviceRegionalCompanyIds", suppliersVO.getServiceRegionalCompanyIds());//服务地区公司
                //入库时间
                map.put("storedStartTime", suppliersVO.getStoredStartTime());
                map.put("storedEndTime", suppliersVO.getStoredEndTime());
                //转不合格时间
                map.put("unqualifiedStartTime", suppliersVO.getUnqualifiedStartTime());
                map.put("unqualifiedEndTime", suppliersVO.getUnqualifiedEndTime());
                //转黑库时间
                map.put("turnToBlackLibraryStartTime", suppliersVO.getTurnToBlackLibraryStartTime());
                map.put("turnToBlackLibraryEndTime", suppliersVO.getTurnToBlackLibraryEndTime());

                if (suppliersVO.getSupplierBigStatus() == 1) {
                    map.put("orderBy", " sup.register_time desc ");
                } else if (suppliersVO.getSupplierBigStatus() == 2) {
                    map.put("orderBy", " rel.turn_to_watch_time desc ");
                } else if (suppliersVO.getSupplierBigStatus() == 3) {
                    map.put("orderBy", " rel.stored_time desc ");
                } else if (suppliersVO.getSupplierBigStatus() == 4) {
                    map.put("orderBy", " rel.unqualified_time desc ");
                } else {
                    map.put("orderBy", " sup.register_time desc ");
                }
                //supplierType  1：待观察列表，2：不合格列表，3：合格列表，4：黑裤列表
                map.put("supplierBigStatus", suppliersVO.getSupplierBigStatus());

                pageCode.setCount(extSSupplierRcRelateMapper.getSuppliersListCounts(map));

                map.put("currentRecordNum", (pageCode.getPageNo() - 1) * pageCode.getPageSize());
                map.put("pageSize", pageCode.getPageSize());

                List<ExtSSuppliers> ls = extSSupplierRcRelateMapper.getSuppliersList(map);
                List<SuppliersResponseVO> result = this.transferTO(ls);
                pageCode.setList(result);

                restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, pageCode);
            } else {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("companyName", suppliersVO.getCompanyName());
                map.put("intentionRegionalCompanyIds", suppliersVO.getIntentionRegionalCompanyIds());
                map.put("supplierStatus", suppliersVO.getSupplierStatus());
                map.put("registerStartTime", suppliersVO.getRegisterStartTime());
                map.put("registerEndTime", suppliersVO.getRegisterEndTime());
                map.put("supplierCategoryIds", suppliersVO.getSupplierCategoryIds());

                map.put("serviceRegionalCompanyIds", suppliersVO.getServiceRegionalCompanyIds());//服务地区公司
                //入库时间
                map.put("storedStartTime", suppliersVO.getStoredStartTime());
                map.put("storedEndTime", suppliersVO.getStoredEndTime());
                //转不合格时间
                map.put("unqualifiedStartTime", suppliersVO.getUnqualifiedStartTime());
                map.put("unqualifiedEndTime", suppliersVO.getUnqualifiedEndTime());
                //转黑库时间
                map.put("turnToBlackLibraryStartTime", suppliersVO.getTurnToBlackLibraryStartTime());
                map.put("turnToBlackLibraryEndTime", suppliersVO.getTurnToBlackLibraryEndTime());

                map.put("orderBy", " rel.update_date desc ");
                map.put("pageSize", 0);

                //supplierType  1：待观察列表，2：不合格列表，3：合格列表，4：黑裤列表
                map.put("supplierBigStatus", suppliersVO.getSupplierBigStatus());

                List<ExtSSuppliers> ls = extSSupplierRcRelateMapper.getSuppliersList(map);
                List<SuppliersResponseVO> result = this.transferTO(ls);
                restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, result);
            }
        } catch (Exception e) {
            e.printStackTrace();
            restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[1], CommonConstants.ERROR_CODES[1]);
        }

        return restReturnResult;
    }


    @Override
    public RestReturnResult getQualifiedSuppliersList(SuppliersRequestVO suppliersVO) {

        RestReturnResult restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[0], CommonConstants.ERROR_CODES[0]);
        try {
            PageCode pageCode = new PageCode(suppliersVO.getPageNumber(), suppliersVO.getPageSize());
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("companyName", suppliersVO.getCompanyName());
            map.put("intentionRegionalCompanyIds", suppliersVO.getIntentionRegionalCompanyIds());
            map.put("supplierStatus", suppliersVO.getSupplierStatus());
            map.put("supplierCategoryIds", suppliersVO.getSupplierCategoryIds());
            map.put("serviceCategoryIds", suppliersVO.getServiceCategoryIds());

            map.put("serviceRegionalCompanyIds", suppliersVO.getServiceRegionalCompanyIds());//服务地区公司
            //入库时间
            map.put("storedStartTime", suppliersVO.getStoredStartTime());
            map.put("storedEndTime", suppliersVO.getStoredEndTime());

            pageCode.setCount(extSSupplierRcRelateMapper.getQualifiedSuppliersListCounts(map));

            map.put("currentRecordNum", (pageCode.getPageNo() - 1) * pageCode.getPageSize());
            map.put("pageSize", pageCode.getPageSize());

            List<ExtSSuppliers> ls = extSSupplierRcRelateMapper.getQualifiedSuppliersList(map);
            List<SuppliersResponseVO> result = this.transferTO(ls);
            pageCode.setList(result);

            restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, pageCode);

        } catch (Exception e) {
            e.printStackTrace();
            restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[1], CommonConstants.ERROR_CODES[1]);
        }

        return restReturnResult;
    }


    @Override
    public List<SSuppliers> selectRankable(RankHistoryReqVO vo) {
        return extSSuppliersMapper.selectRankable(vo);
    }

    @Override
    public List<SuppliersResponseVO> getQualifiedSuppliersListNoPage(SuppliersRequestVO suppliersVO) {
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("companyName", suppliersVO.getCompanyName());
            map.put("intentionRegionalCompanyIds", suppliersVO.getIntentionRegionalCompanyIds());
            map.put("supplierStatus", suppliersVO.getSupplierStatus());
            map.put("supplierCategoryIds", suppliersVO.getSupplierCategoryIds());
            map.put("serviceCategoryIds", suppliersVO.getServiceCategoryIds());

            map.put("serviceRegionalCompanyIds", suppliersVO.getServiceRegionalCompanyIds());//服务地区公司
            //入库时间
            map.put("storedStartTime", suppliersVO.getStoredStartTime());
            map.put("storedEndTime", suppliersVO.getStoredEndTime());

            List<ExtSSuppliers> ls = extSSupplierRcRelateMapper.getQualifiedSuppliersList(map);
            return this.transferTO(ls);
        } catch (Exception e) {
        }
        return null;
    }

    @Override
    public String getRegionalCompanyNamesByIds(String regionalCompanyIds) {
        if (StringUtils.isBlank(regionalCompanyIds)) {
            return null;
        }
        String[] ids = regionalCompanyIds.split(",");
        List<String> idList = new ArrayList<>();
        for (String id : ids) {
            idList.add(id);
        }
        List<SRegionalCompany> regionalCompanyList = sRegionalCompanyMapper.findRegionalCompanyByIds(idList);
        StringBuffer result = new StringBuffer();
        if (regionalCompanyList != null && regionalCompanyList.size() > 0) {
            for (int i = 0; i < regionalCompanyList.size(); i++) {
                if (i == 0) {
                    result.append(regionalCompanyList.get(i).getRegionalCompanyName());
                } else {
                    result.append("," + regionalCompanyList.get(i).getRegionalCompanyName());
                }
            }
        }
        return result.toString();
    }

    public <T> void compare(T objNew, T objOld, String classRecordId, String suppliersId, SSupplierRcRelate sSupplierRcRelate, String userId) throws IllegalAccessException, ParseException {
//			Map<String, String> result = new HashMap<String, String>();
        if (sSupplierRcRelate != null && SupplierStatusEnum.QUALIFIED.getCode().equals(sSupplierRcRelate.getSupplierStatus() + "")) {
            Field[] fs = null;
            String className = null;
            Integer actionType = 0;
            if (objNew == null && objOld != null) {
                actionType = EnumConstant.actionType.delete.getCode();
                fs = objOld.getClass().getDeclaredFields();
                className = objOld.getClass().getSimpleName();
            } else if (objNew != null && objOld == null) {
                actionType = EnumConstant.actionType.add.getCode();
                fs = objNew.getClass().getDeclaredFields();
                className = objNew.getClass().getSimpleName();
            } else if (objNew != null && objOld != null) {
                actionType = EnumConstant.actionType.update.getCode();
                fs = objNew.getClass().getDeclaredFields();
                className = objNew.getClass().getSimpleName();
            } else {
                return;
            }
            for (Field f : fs) {
                f.setAccessible(true);
                Object v1 = null, v2 = null;
                if (objNew != null) {
                    v1 = f.get(objNew);
                }
                if (objOld != null) {
                    v2 = f.get(objOld);
                }
                if ((v2 == null && v1 != null) || (v1 == null && v2 != null) || !equals(v1, v2)) {
                    EntityWrapper wrapper = new EntityWrapper<>();
                    SSupplierFormFields entity = new SSupplierFormFields();
                    entity.setClassName(className);
                    entity.setClassFieldCode(f.getName());
                    wrapper.setEntity(entity);
                    SSupplierFormFields sSupplierFormFields = sSupplierFormFieldsService.selectOne(wrapper);
                    if (sSupplierFormFields != null) {
                        SSupplierFormModifyMapping sSupplierFormModifyMapping = new SSupplierFormModifyMapping();
                        BeanUtils.copyProperties(sSupplierFormFields, sSupplierFormModifyMapping);
                        sSupplierFormModifyMapping.setId(IdGen.uuid());
                        sSupplierFormModifyMapping.setBaseFeilds(userId, "", 0, true);
                        sSupplierFormModifyMapping.setClassRecordId(classRecordId);
                        sSupplierFormModifyMapping.setClassName(className);
                        sSupplierFormModifyMapping.setSuppliersId(suppliersId);
                        sSupplierFormModifyMapping.setDongFlag(0);
                        sSupplierFormModifyMapping.setActionType(actionType);
                        if (v2 != null) {
                            sSupplierFormModifyMapping.setModifiedBeforeValue(v2.toString());
                        }
                        if (v1 != null) {
                            sSupplierFormModifyMapping.setModifiedAfterValue(v1.toString());
                        }
                        if ("enterpriseCharacterize".equals(sSupplierFormFields.getClassFieldCode())) {//企业性质
                            if (v2 != null)
                                sSupplierFormModifyMapping.setModifiedBeforeName(EnumConstant.recommenderType.getDesc(v2.toString()));
                            if (v1 != null)
                                sSupplierFormModifyMapping.setModifiedAfterName(EnumConstant.recommenderType.getDesc(v1.toString()));
                        } else if ("taxipayerStatus".equals(sSupplierFormFields.getClassFieldCode())) {//纳税人状态
                            if (v2 != null)
                                sSupplierFormModifyMapping.setModifiedBeforeName(EnumConstant.taxipayerStatus.getDesc(v2.toString()));
                            if (v1 != null)
                                sSupplierFormModifyMapping.setModifiedAfterName(EnumConstant.taxipayerStatus.getDesc(v1.toString()));
                        } else if ("supplierServiceCategoryIds".equals(sSupplierFormFields.getClassFieldCode())
                                || "supplierCategoryIds".equals(sSupplierFormFields.getClassFieldCode())) {//分类
                            if (v2 != null) {
                                String[] supplierServiceCategoryIdArr = v2.toString().split(",");
                                String supplierServiceCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierServiceCategoryIdArr);
                                sSupplierFormModifyMapping.setModifiedBeforeName(supplierServiceCategoryNames);
                            }
                            if (v1 != null) {
                                String[] supplierServiceCategoryIdArr = v1.toString().split(",");
                                String supplierServiceCategoryNames = sSuppliersCategoryService.getSupplierCategoryNames(supplierServiceCategoryIdArr);
                                sSupplierFormModifyMapping.setModifiedAfterName(supplierServiceCategoryNames);
                            }
                        } else if ("intentionRegionalCompanyIds".equals(sSupplierFormFields.getClassFieldCode())) {//意向地区公司
                            if (v2 != null) {
                                String[] intentionRegionalCompanyIdArr = v2.toString().split(",");
                                String intentionRegionalCompanyNames = sRegionalCompanyService.getRegionalCompanyNames(intentionRegionalCompanyIdArr);
                                sSupplierFormModifyMapping.setModifiedBeforeName(intentionRegionalCompanyNames);
                            }
                            if (v1 != null) {
                                String[] intentionRegionalCompanyIdArr = v1.toString().split(",");
                                String intentionRegionalCompanyNames = sRegionalCompanyService.getRegionalCompanyNames(intentionRegionalCompanyIdArr);
                                sSupplierFormModifyMapping.setModifiedAfterName(intentionRegionalCompanyNames);
                            }
                        } else if ("companyListed".equals(sSupplierFormFields.getClassFieldCode()) ||//是否上市公司（0：否，1：是）
                                "fullMemberFlag".equals(sSupplierFormFields.getClassFieldCode())) {//是否全装联会员（0：否，1：是）
                            if (v2 != null) {
                                String flag = v2.toString();
                                String name = flag.equals(CommonConstants.YES_INTEGER + "") ? "是" : "否";
                                sSupplierFormModifyMapping.setModifiedBeforeName(name);
                            }
                            if (v1 != null) {
                                String flag = v1.toString();
                                String name = flag.equals(CommonConstants.YES_INTEGER + "") ? "是" : "否";
                                sSupplierFormModifyMapping.setModifiedAfterName(name);
                            }
                        } else if ("headquartersProvince".equals(sSupplierFormFields.getClassFieldCode())) {//所在区域省
                            if (v2 != null) {
                                String value = v2.toString();
                                SysArea sysArea = sysAreaService.selectById(value);
                                if (sysArea != null)
                                    sSupplierFormModifyMapping.setModifiedBeforeName(sysArea.getAreaName());
                            }
                            if (v1 != null) {
                                String value = v1.toString();
                                SysArea sysArea = sysAreaService.selectById(value);
                                if (sysArea != null)
                                    sSupplierFormModifyMapping.setModifiedAfterName(sysArea.getAreaName());
                            }
                        } else if ("undertakeAreas".equals(sSupplierFormFields.getClassFieldCode())) {//承接省份
                            if (v2 != null) {
                                String value = v2.toString();
                                if (StringUtils.isNotEmpty(value)) {
                                    String[] idArr = value.split(",");
                                    String names = sysAreaService.getAreaNames(idArr);
                                    if (StringUtils.isNotEmpty(names))
                                        sSupplierFormModifyMapping.setModifiedBeforeName(names);
                                }
                            }
                            if (v1 != null) {
                                String value = v1.toString();
                                if (StringUtils.isNotEmpty(value)) {
                                    String[] idArr = value.split(",");
                                    String names = sysAreaService.getAreaNames(idArr);
                                    if (StringUtils.isNotEmpty(names))
                                        sSupplierFormModifyMapping.setModifiedAfterName(names);
                                }
                            }
                        } else {
                            if ("datetime".equals(sSupplierFormModifyMapping.getTableFiledType())) {
                                SimpleDateFormat sfEnd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                SimpleDateFormat sfStart = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", java.util.Locale.ENGLISH);
                                if (v2 != null) {
                                    sSupplierFormModifyMapping.setModifiedBeforeValue(sfEnd.format(sfStart.parse(v2.toString())));
                                    sSupplierFormModifyMapping.setModifiedBeforeName(sfEnd.format(sfStart.parse(v2.toString())));
                                }
                                if (v1 != null) {
                                    sSupplierFormModifyMapping.setModifiedAfterValue(sfEnd.format(sfStart.parse(v1.toString())));
                                    sSupplierFormModifyMapping.setModifiedAfterName(sfEnd.format(sfStart.parse(v1.toString())));
                                }
                            } else {
                                if (v2 != null) sSupplierFormModifyMapping.setModifiedBeforeName(v2.toString());
                                if (v1 != null) sSupplierFormModifyMapping.setModifiedAfterName(v1.toString());
                            }
                        }

                        sSupplierFormModifyMappingService.insert(sSupplierFormModifyMapping);
                    }
//					result.put(f.getName(), String.valueOf(equals(v1, v2)));
                }
            }
//			return result;
        }
    }

    public boolean equals(Object obj1, Object obj2) {
        if (obj1 == obj2) {
            return true;
        }
        if (obj1 == null || obj2 == null) {
            return false;
        }
        return obj1.equals(obj2);
    }


    private boolean saveSHistoryComment(String relatedId, String userId) {
        SHistoryComment sHistoryComment = new SHistoryComment();
        sHistoryComment.setId(IdGen.uuid());
        sHistoryComment.setModelType(HistoryCommentModelTypeEnum.HistoryCommentModelType3.getCode());//功能模块（1：供方信息审核历程，2：供方现场考察组员意见，3：供方评估审核，
        sHistoryComment.setRelatedId(relatedId);
        sHistoryComment.setSubRelatedId(relatedId);
        sHistoryComment.setNodeName(sCommentConfigService.getValueByCode(CommentConfigEnum.SUPPLIER_EXTRANET_ADD_HISTORY_COMMENT_NODE_NAME.getCode()));
        sHistoryComment.setCommentContent(null);
        sHistoryComment.setActionName(sCommentConfigService.getValueByCode(CommentConfigEnum.SUPPLIER_EXTRANET_ADD_HISTORY_COMMENT_ACTION_NAME.getCode()));
        sHistoryComment.setCommentType(HistoryCommentTypeEnum.INTRANET.getCode());//'类型（1：内网，2：外网，3：内外网共用）
        sHistoryComment.setSetupTime(new Date());
        sHistoryComment.setBaseFeilds(userId, null, 0, true);
        boolean historyCommentFlag = sHistoryCommentService.insert(sHistoryComment);
        return historyCommentFlag;
    }


    @Override
    public SSuppliers getBySysUserId(String userId) {
        EntityWrapper entityWrapper = new EntityWrapper();
        SSuppliers sSuppliers = new SSuppliers();
        sSuppliers.setSysUserId(userId);
        entityWrapper.setEntity(sSuppliers);
        return selectOne(entityWrapper);
    }

    /**
     * 母公司列表
     *
     * @param supplierStatus
     * @return
     */
    @Override
    public RestReturnResult getCompanyListByStatus(String supplierStatus) {
        RestReturnResult restReturnResult = RestReturnResult.error();
        List<ExtSSuppliers> ls = extSSuppliersMapper.getCompanyListByStatus(supplierStatus, null);
        List<ParentCmpyReponseVO> resultLs = new ArrayList();
        for (ExtSSuppliers extSSuppliers : ls) {
            ParentCmpyReponseVO obj = new ParentCmpyReponseVO();
            obj.setId(extSSuppliers.getId());
            obj.setCreditLicenseCodeFlag(extSSuppliers.getCreditLicenseCodeFlag());
            obj.setBusinessLicenseNumber(extSSuppliers.getBusinessLicenseNumber());
            obj.setLegalRepresentative(extSSuppliers.getLegalRepresentative());
            obj.setRelateParentCompanyName(extSSuppliers.getCompanyName());
            obj.setRegistAddress(extSSuppliers.getHeadquartersAddress());
            obj.setSocialCreditCode(extSSuppliers.getSocialCreditCode());
            resultLs.add(obj);
        }
        restReturnResult = RestReturnResult.success();
        restReturnResult.setData(resultLs);
        return restReturnResult;
    }

    @Override
    public RestReturnResult checkLoginName(String loginName, int checkType) {
        RestReturnResult restReturnResult = RestReturnResult.error();
        try {
            SysUser sysUser = sysUserService.getSysUserByUserName(loginName);

            if (checkType == 1) {//注册
                if (sysUser != null) {
                    restReturnResult = new RestReturnResult(CommonConstants.FAIL, "用户名已存在");
                } else {
                    restReturnResult = RestReturnResult.success();
                }
            } else if (checkType == 2) {//登录/修改密码
                if (sysUser != null) {
                    restReturnResult = RestReturnResult.success();
                } else {
                    restReturnResult = new RestReturnResult(CommonConstants.FAIL, "用户名不存在");
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            restReturnResult = RestReturnResult.error();
        }
        return restReturnResult;
    }

    @Override
    public RestReturnResult checkCodeOrNumber(SubSupplierRequestVO subSupplierRequestVO) {
        RestReturnResult restReturnResult = RestReturnResult.error();
        try {
            if (StringUtils.isEmpty(subSupplierRequestVO.getSocialCreditCode()) && StringUtils.isEmpty(subSupplierRequestVO.getBusinessLicenseNumber())) {
                restReturnResult = new RestReturnResult(CommonConstants.FAIL, "营业执照号/统一社会信用代码 必填");
            } else {
                SSuppliers sSuppliers = new SSuppliers();
                if (subSupplierRequestVO.getCreditLicenseCodeFlag() == 1) {//信用代码或营业执照号（1：统一社会信用代码， 2：营业执照号）
                    sSuppliers.setSocialCreditCode(subSupplierRequestVO.getSocialCreditCode());
                } else {
                    sSuppliers.setBusinessLicenseNumber(subSupplierRequestVO.getBusinessLicenseNumber());
                }
                sSuppliers.setId(subSupplierRequestVO.getSupplierId());
                Integer count = extSSuppliersMapper.findSupplierCount(sSuppliers);
                if (count != null && count > 0) {
                    restReturnResult = new RestReturnResult(CommonConstants.FAIL, "营业执照号/统一社会信用代码 已存在");
                } else {

                    if (subSupplierRequestVO.getCreditLicenseCodeFlag() == 2
                            && StringUtils.isNotBlank(sSuppliers.getBusinessLicenseNumber())) {
                        boolean flag = synDataService.checkSupplierLicenseNo(sSuppliers.getBusinessLicenseNumber());

                        if (!flag) {
                            restReturnResult = new RestReturnResult(CommonConstants.FAIL, "该供应商已经存在");
                        } else {
                            restReturnResult = RestReturnResult.success();
                        }

                    } else {
                        restReturnResult = RestReturnResult.success();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            restReturnResult = RestReturnResult.error();
        }
        return restReturnResult;
    }

    @Override
    public String getSupplierIdBySysId(String userId) {
        EntityWrapper entityWrapper = new EntityWrapper();
        SSuppliers sSuppliers = new SSuppliers();
        sSuppliers.setSysUserId(userId);
        entityWrapper.setEntity(sSuppliers);
        return selectOne(entityWrapper).getId();
    }

    /**
     * 获取可供选择的供方
     */
    @Override
    public RestReturnResult getSelectSupplierListByCompanyIdAndServiceCategoryIds(String regionalCompanyId, String purchaseClassification) {

        try {
            List<ExtSSuppliers> list = extSSuppliersMapper.getSelectSupplierListByCompanyIdAndServiceCategoryIds(regionalCompanyId, purchaseClassification);

            return new RestReturnResult(CommonConstants.SUCCESS, list);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("=========getSelectSupplierList===============e:=====" + e.getMessage());
            throw new RuntimeException(e.getMessage(), e.getCause());
        }

    }

    @Override
    public RestReturnResult getSuppliersAll(SuppliersRequestVO suppliersVO) {
        RestReturnResult restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[0], CommonConstants.ERROR_CODES[0]);
        try {
            if (suppliersVO.getPageFlag() != null &&
                    suppliersVO.getPageFlag() == CommonConstants.YES_INTEGER) {
                PageCode pageCode = new PageCode(suppliersVO.getPageNumber(), suppliersVO.getPageSize());

                Map<String, Object> map = new HashMap<String, Object>();
                map.put("companyName", suppliersVO.getCompanyName());

                pageCode.setCount(extSSuppliersMapper.getSuppliersAllCount(map));

                map.put("currentRecordNum", (pageCode.getPageNo() - 1) * pageCode.getPageSize());
                map.put("pageSize", pageCode.getPageSize());

                List<ExtSSuppliers> ls = extSSuppliersMapper.getSuppliersAll(map);
                List<SuppliersResponseVO> result = this.transferTO(ls);
                pageCode.setList(result);
                restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, pageCode);
            } else {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("companyName", suppliersVO.getCompanyName());
                map.put("pageSize", 0);
                List<ExtSSuppliers> ls = extSSuppliersMapper.getSuppliersAll(map);
                List<SuppliersResponseVO> result = this.transferTO(ls);
                restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, result);
            }
        } catch (Exception e) {
            e.printStackTrace();
            restReturnResult = new RestReturnResult(CommonConstants.FAIL, CommonConstants.ERROR_DESCS[1], CommonConstants.ERROR_CODES[1]);
        }

        return restReturnResult;
    }

    @Override
    public void batchSynSuppliers2Mdm() {
        List<ExtSSuppliers> ls = extSSuppliersMapper.getUnSynSuppliersList();
        for (SSuppliers sSuppliers : ls) {
            sSuppliersSubmitOldSysInterfaceService.abutmentSuplierData2MDM(sSuppliers, true);
        }
    }

    @Override
    public SupplierSyncVO getSupplierListForSyncCost() {
        List<ExtSSuppliers> ls = extSSuppliersMapper.getSupplierListForSyncCost();
        List<SSupplierBankAccount> ba = sSupplierBankAccountService.selectListForSyncCost();
        SupplierSyncVO vo = new SupplierSyncVO();
        vo.setSuppliersList(ls);
        vo.setSupplierBankAccountList(ba);
        return vo;
    }
}
